英文:
Creating a Slice that contains a map
问题
我正在尝试创建一个包含切片和映射的数据结构。这是我的代码:
data := map[string]interface{}{"Offset": "0", "Properties": []string{}, "Category": "all", "Locations": []string{}, "Accounts": "100"}
我需要"Properties"元素包含一个像这样的映射:
{"key": "Type", "value": "User"}
这似乎比应该的要难,或者可能是我太蠢了。
英文:
I'm trying to create a data structure that includes a slice containing a map. This is what I have:
data := map[string]interface{}{"Offset": "0", "Properties": []string{}, "Category": "all", "Locations": []string{}, "Accounts": "100" }
I need the "properties" element to include a map that looks like this:
{"key": "Type", "value": "User"}
This seems to be harder than it should be, or maybe I'm just being stupid.
答案1
得分: 2
以下是您要翻译的内容:
像这样的代码应该是您想要的(playground)
data := map[string]interface{}{"Offset": "0",
"Properties": map[string]string{
"key": "Type",
"value": "User",
},
"Category": "all",
"Locations": []string{},
"Accounts": "100",
}
英文:
Something like this should be what you want (playground)
data := map[string]interface{}{"Offset": "0",
"Properties": map[string]string{
"key": "Type",
"value": "User",
},
"Category": "all",
"Locations": []string{},
"Accounts": "100",
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论