以下是从接收到的数据
{
"details": [
{
"attdetails": [
{
"id": "a48c8539-caaf-49a5-9346-8e88e60e7af4",
"name": "compute01"
},
{
"id": "a48c8539-caaf-49a5-9346-8e88e60e7af4",
"name": "compute02"
}
],
"name": "item1"
},
{
"attdetails": [
{
"id": "85bdafa7-274e-4180-b76f-12f390a274fc",
"name": "compute03"
},
{
"id": "85bdafa7-274e-4180-b76f-12f390a274fc",
"name": "compute04"
}
],
"name": "item1"
}
]
}
我正在尝试使用以下数据创建 JSON:
["item1":
{"compute01": "a48c8539-caaf-49a5-9346-8e88e60e7af4"},
{"compute02": "a48c8539-caaf-49a5-9346-8e88e60e7af4"},
{"compute03": "a48c8539-caaf-49a5-9346-8e88e60e7af4"},
{"compute04": "a48c8539-caaf-49a5-9346-8e88e60e7af4"}
]
我尝试创建映射[字符串]接口,但我无法将它们分组在一起并将它们添加到数组中到特定的键。
以下是我正在尝试使用的示例代码:
var childrens map[string]interface{}
for _, a := range atts {
att, ok := childrens[a.Name]
if !ok {
childrens[a.Name] = make([]map[string]string, 0)
}
var c map[string]string
for _, each := range a.Details {
c[each.Name] = each.Value
}
childrens[a.Name] = append(c, childrens[a.Name])
}
12345678_0001
当年话下
胡说叔叔
犯罪嫌疑人X
相关分类