Qyouu
我不完全确定您在这里所说的对象是什么意思,但实现这一目标的一种方法是通过.map例如:package mainimport "fmt"func main(){ type Person struct { ID string `json:"id"` Name string `json:"name"` Address string `json:"address"` } var Group = []Person{ { ID: "1", Name: "Linda", Address: "London", }, { ID: "2", Name: "George", Address: "Paris", }, { ID: "3", Name: "John", Address: "Amsterdam", }, } personMap := map[string]Person{} for _, person := range Group { personMap[person.Name] = person } fmt.Println(personMap) // Outputs: map[George:{2 George Paris} John:{3 John Amsterdam} Linda:{1 Linda London}]}然后,您可以通过以下方式从地图访问aPersonpersonMap["Linda"]