nilnil
datadata["a"]"a"nildata["a"]["w"]

您必须先初始化 map,然后再在其中存储元素,例如:

var data = map[string]map[string]string{}

data["a"] = map[string]string{}
data["b"] = make(map[string]string)
data["c"] = make(map[string]string)

data["a"]["w"] = "x"
data["b"]["w"] = "x"
data["c"]["w"] = "x"
fmt.Println(data)

输出(在Go Playground上尝试):

map[a:map[w:x] b:map[w:x] c:map[w:x]]
var data = map[string]string{}

请注意,您还可以使用复合文字来初始化嵌套 map:

var data = map[string]map[string]string{
    "a": map[string]string{},
    "b": map[string]string{},
    "c": map[string]string{},
}

data["a"]["w"] = "x"
data["b"]["w"] = "x"
data["c"]["w"] = "x"
fmt.Println(data)

输出是相同的。Go Playground上尝试一下