我有以下 json:
{"results":
[{"columns":["room_id","player_name","player_ip"],
"types":["integer","text","text"],
"values":[[1,"alice","127.0.0.1"]
[1,"bob","127.0.0.1"]],
"time":0.00018839100000000002}]}
其中值可以在其中包含任意数量的元素 []。当我尝试将 json 解组到一个结构中时,“values”标签没有被正确解析
结构:
type queryResults struct {
Results []struct {
Columns []string `json:"columns"`
Types []string `json:"types"`
Values []struct {
Room_id int
Player_name string
Player_ip string
} `json:"values"`
Time float64 `json:"time"`
} `json:"results"`
}
代码:
//jsonString is the string input to Unmarshal
resultjson := queryResults{}
json.Unmarshal([]byte(jsonString), &resultjson)
fmt.Printf("%+v",resultjson)
电流输出:
{Results:
[{Columns:[room_id player_name player_ip]
Types:[integer text text]
Values:[{room_id:0 player_name: player_ip:}
{room_id:0 player_name: player_ip:}]
Time:0.00018839100000000002}]}
预期输出:
{Results:
[{Columns:[room_id player_name player_ip]
Types:[integer text text]
Values:[{room_id:1 player_name:alice player_ip:127.0.0.1}
{room_id:1 player_name:bob player_ip:127.0.0.1}]
Time:0.00018839100000000002}]}
暮色呼如
翻阅古今
相关分类