2021-05-20
1package main 2 3import "fmt" 4 5var testMap = map[string]map[string]struct { 6 Name string 7}{ 8 "first": {"second": {Name: "12312"}}, 9 "second": {"second": {"12312"}}, 10} 11 12func main() { 13 d := testMap["first"]["second"].Name 14 fmt.Printf("++-%v-++\n", d) 15 16 17 // map 不会报 nil 18 c := testMap["first22"]["second"].Name 19 fmt.Printf("++-%v-++\n", c) 20} 结果
1++-12312-++ 2++--++