data := map[string]interface{}{}
jsonStrs := []string{
`{"k1":"v1","k2":"v2"}`,
`{"k3":"v3","k2":2}`,
`{"k4":"v4","k5":"v5"}`,
}
for _, s := range jsonStrs {
json.Unmarshal([]byte(s), &data)
}
for循环结束后data中会包含k1,k2,k3,k4,k5五个元素
data := map[string]interface{}{}
jsonStrs := []string{
`{"k1":"v1","k2":"v2"}`,
`{"k3":"v3","k2":2}`,
`{"k4":"v4","k5":"v5"}`,
}
for _, s := range jsonStrs {
json.Unmarshal([]byte(s), &data)
}
for循环结束后data中会包含k1,k2,k3,k4,k5五个元素
本文标题:map接收json unmarshal出来的数据时注意
本文链接:https://www.haomeiwen.com/subject/palpuxtx.html
网友评论