packagemain import"fmt" typePersonstruct{ IDstring Namestring Addrstring } funcmain(){ varpersonsmap[string]Person=make(map[string]Person) persons["123"]=Person{"123","heihei","haha"} p,ok:=persons["123"] ifok{ fmt.Println(p.Name) } fmt.Println("----") p2:=map[string]Person{ "111":Person{"111","11111","2222"},} pp,oks:=p2["111"] ifoks{ fmt.Println(pp.Addr) } }原文链接:https://www.f2er.com/go/190765.html