结构体转JSON
package main

import (
    "encoding/json"
    "fmt"
)

type Zhihu struct {
    Article string
    Goods   int
}

func main() {

    z := Zhihu{
        Article: "Go语言结构体和JSON相互转换",
        Goods:   100,
    }

    output, _ := json.Marshal(&z)

    fmt.Println(string(output))

}

JSON转结构体

package main

import (
    "encoding/json"
    "fmt"
)

type Zhihu struct {
    Article string
    Goods   int
}

func main() {

    var s Zhihu
    
    j := `{"Acrticle":"Go语言结构体和JSON相互转换","Goods":100}`

    

    json.Unmarshal([]byte(j),&s)

    fmt.Println(string(s.Acrticle))

    fmt.Println(int(s.Goods))

}