1 回答
TA贡献1807条经验 获得超9个赞
您需要将数据解组为 map[string]map[string]string,如下所示:
jsonData:="{\"key1\":{\"col1\":\"Data11\",\"col2\":\"Data12\",\"col3\":\"Data13\",\"col4\":\"Data14\"}, \"key2\":{\"col1\":\"Data21\",\"col2\":\"Data22\",\"col3\":\"Data23\",\"col4\":\"Data24\"}, \"key3\":{\"col1\":\"Data31\",\"col2\":\"Data32\",\"col3\":\"Data33\",\"col4\":\"Data34\"}, \"key4\":{\"col1\":\"Data41\",\"col2\":\"Data42\",\"col3\":\"Data43\",\"col4\":\"Data44\"}, \"key5\":{\"col1\":\"Data51\",\"col2\":\"Data52\",\"col3\":\"Data53\",\"col4\":\"Data54\"}, \"key6\":{\"col1\":\"Data61\",\"col2\":\"Data62\",\"col3\":\"Data63\",\"col4\":\"Data64\"}}"
var jsonObject map[string]map[string]string
json.Unmarshal([]byte(jsonData),&jsonObject)
for k:=range jsonObject{
fmt.Println(k ," has " , len(jsonObject[k]) , " fields")
for j:=range jsonObject[k]{
fmt.Println(j , "=",jsonObject[k][j] )
}
}
- 1 回答
- 0 关注
- 85 浏览
添加回答
举报