package main import "fmt" type Person struct { ID string Name string Addr string } func main() { var persons map[string] Person = make(map[string] Person) persons["123"] = Person {"123", "heihei", "haha"} p, ok := persons["123"] if ok { fmt.Println(p.Name) } fmt.Println("----") p2 := map[string] Person { "111" : Person {"111", "11111", "2222"}, } pp, oks := p2["111"] if oks { fmt.Println(pp.Addr) } }
有疑问加站长微信联系(非本文作者)