import "encoding/json"
func Marshal(v interface{}) ([]byte, error)
func Marshal(v interface{}) ([]byte, error)
type ColorGroup struct {ID intName string //
记得
大写!!!!
Colors []string}group := ColorGroup{ID: 1,Name: "Reds",Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},}b, err := json.Marshal(group)
func Unmarshal(data []byte, v interface{}) error
var jsonBlob = []byte(`[{"Name": "Platypus", "Order": "Monotremata"},{"Name": "Quoll", "Order": "Dasyuromorphia"}]`)type Animal struct {Name stringOrder string}var animals []Animalerr := json.Unmarshal(jsonBlob, &animals)
评论
发表评论