Arrays 动态数组json解析
我正在尝试解析json,以使其返回空对象: Json对象:Arrays 动态数组json解析,arrays,json,go,Arrays,Json,Go,我正在尝试解析json,以使其返回空对象: Json对象: `{ "names": [ { "David": { "id": "100", "country": "usa", "group": [ "A1", "A2" ]
`{
"names": [
{
"David": {
"id": "100",
"country": "usa",
"group": [
"A1",
"A2"
]
}
},
{
"John": {
"id": "1",
"country": "uk",
"group": [
"A1",
"A2"
]
}
}
]
}`
GoLang结构:
type Data struct {
Names []Names `json:"names"`
}
type Names struct {
ID string `json:"id"`
Country string `json:"country"`
Group []string `json:"group"`
}
数组包含2个元素David,John的问题是它返回空对象,因为解析器在提取字符串David,John时有问题。struct
数据的
map[string]名称
而不是[]名称
。
因此,只需将其更改为:
Names []map[string]Names `json:"names"`
查看完整的可运行代码。您好,您能提供反序列化此JSON的代码示例吗?很好,它的工作,字符串数组,映射