Define struct//initial capitalization, JSON: "msg_id" is the Tagtype Message struct {MsgId string ' JSON: "msg_id" ' content string ' JSON: "Content" }//json Sequence Number deserialization func t3_1 () {msg: = message{"msgid_001", "contente2222222222"}str, err: = json. Marshal (msg)//output {"msg_id": "msgid_001", "Content": "contente2222222222"}fmt. PRINTLN (String (str), err) var msg1 message//str: = ' {"Changes": [{"Armid": 3, "index": 5}, {"Armid": 3, "index": 6}]} '// Deserialize to Stucterr = json. Unmarshal (str, &MSG1)//output {msgid_001 contente2222222222}fmt. PRINTLN (MSG1)//deserialize to Mapvar msg2 Map[string]stringerr = json. Unmarshal (str, &MSG2)//Output map[msg_id:msgid_001 content:contente2222222222]fmt. Println (MSG2)}
The following article is written in more detail
Address: http://www.cnblogs.com/littlepanpc/p/3965238.html
Go practice 4--json Sequence Number deserialization