最近在看go语言的map,struct的操作,找到以下的简单方法,直接代码,留作参考
package main
import "fmt"
type Person struct {
Id string `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Sex int `json:"sex"`
}
func main() {
var dev = make(map[string]interface{})
dev["person1"] = Person{
Id: "11",
Name: "Black",
Age: 10,
Sex: 1,
}
dev["person2"] = Person{
Id: "12",
Name: "Green",
Age: 15,
Sex: 2,
}
person1:=dev["person1"].(Person)
person2:=dev["person2"].(Person)
fmt.Println(person1)
fmt.Println(person1.Id,person1.Name,person1.Age,person1.Sex)
fmt.Println(person2)
fmt.Println(person2.Id,person2.Name,person2.Age,person2.Sex)
}