标签:blog http ar div sp log on html c
//定义结构体
//首字母大写 , json:"msg_id" 是 tag
type Message struct {
MsgId string `json:"msg_id"`
Content string `json:"content"`
}
//json 序列号反序列化
func T3_1() {
msg := Message{"msgid_001", "contente2222222222"}
str, err := json.Marshal(msg)
//输出 {"msg_id":"msgid_001","content":"contente2222222222"}
fmt.Println(string(str), err)
var msg1 Message
// str := `{"changes": [{"armid":3,"Index":5}, {"armid":3,"Index":6}]}`
//反序列化为 stuct
err = json.Unmarshal(str, &msg1)
//输出 {msgid_001 contente2222222222}
fmt.Println(msg1)
//反序列化为map
var msg2 map[string]string
err = json.Unmarshal(str, &msg2)
//输出 map[msg_id:msgid_001 content:contente2222222222]
fmt.Println(msg2)
}
下面的文章 写的比较详细
地址:http://www.cnblogs.com/littlepanpc/p/3965238.html
标签:blog http ar div sp log on html c
原文地址:http://www.cnblogs.com/ilahsa/p/3968921.html