2 回答
TA贡献1817条经验 获得超14个赞
使用复合文字:
places := struct {
Country map[string][]string
}{
Country: map[string][]string{"india": {"Chennai", "Hyderabad", "Kolkata"}},
}
或者,如果您想使用make,您可以使用多个语句来实现:
places := struct {
Country map[string][]string
}{
Country: make(map[string][]string),
}
places.Country["india"] = []string{"Chennai", "Hyderabad", "Kolkata"}
// or
places := struct { Country map[string][]string }
places.Country = make(map[string][]string)
places.Country["india"] = []string{"Chennai", "Hyderabad", "Kolkata"}
TA贡献1783条经验 获得超4个赞
这应该有效:https ://goplay.space/#gfSDLS79AHB
package main
import (
"fmt"
)
func main() {
places := struct {
Country map[string][]string
}{
Country: map[string][]string{"india": {"Chennai", "Hyderabad", "Kolkata"}},
}
fmt.Println("places =", places)
}
- 2 回答
- 0 关注
- 119 浏览
添加回答
举报