我目前的代码是:
name := "John"
id := "1234"
c := make(map[string][]string)
c["d"] = make([]string, len(d))
c["l"] = make([]string, len(l))
copy(c["d"], d)
copy(c["l"], l)
c["test"] = name
c["id"] = id
假设d& l都是[]字符串。围棋不让我这样做。有没有办法让我能够实现这样的JSON:
{ “名字”:“约翰”, “id”:“1234”, “d”:[ 123, 456 ] “l”:[ 123, 456 ] }
答案 0 :(得分:2)
map[string]interface{}
代替。 map[string]interface{}
的示例:
name := "John"
id := "1234"
l, d := []string{"123", "456"}, []string{"789", "987"}
c := map[string]interface{}{
"d": d,
"l": l,
"test": name,
"id": id,
}