This is a creation in Article, where the information may have evolved or changed.
1 Package Main2 3 Import (4 "bytes"5 "Encoding/json"6 "FMT"7 )8 9Type Colorgroupstruct {TenIdint OneNamestring AColors []string - } - the Func Main () { - - //---------------Marshal -Group: =colorgroup{ +Id:1, -Name:"Reds", +Colors: []string{"Crimson","Red","Ruby","Maroon"}, A } atB, err: =JSON. Marshal (group) - ifErr! =Nil { -Fmt. Println ("Error:", Err) - } - //OS. Stdout.write (b) -Fmt. Println (string(b[:])) in - //---------------Unmarshal to varJsonblob = []byte(`[ +{"ID":1,"Name":"Reds1","Colors":["Crimson","Red1","Ruby1","Maroon1"]}, -{"ID":2,"Name":"Reds2","Colors":["Crimson","Red2","Ruby2","Maroon2"]}, the{"ID":3,"Name":"REDS3","Colors":["Crimson","Red3","Ruby3","Maroon3"]} * ]`) $ Panax Notoginseng varAnimals []colorgroup -Error: = JSON. Unmarshal (Jsonblob, &animals) the ifError! =Nil { +Fmt. Println ("Error:", error) A } the + //FMT. Printf ("%+v", Animals) - //FMT. PRINTLN (Animals) $ forI, X: =Range Animals { $ FMT. Println (i, X) - - } the //---------------Indent -DST: =New(bytes. Buffer)WuyiJson. Indent (DST, Jsonblob,"##","**") the FMT. Println (DST) -}