github.com/zhongdalu/gf@v1.0.0/geg/util/gconv/gconv_struct5.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "github.com/zhongdalu/gf/g" 6 "github.com/zhongdalu/gf/g/util/gconv" 7 ) 8 9 func main() { 10 type Score struct { 11 Name string 12 Result int 13 } 14 type User struct { 15 Scores []Score 16 } 17 18 user := new(User) 19 scores := map[string]interface{}{ 20 "Scores": map[string]interface{}{ 21 "Name": "john", 22 "Result": 100, 23 }, 24 } 25 26 // 嵌套struct转换,属性为slice类型,数值为map类型 27 if err := gconv.Struct(scores, user); err != nil { 28 fmt.Println(err) 29 } else { 30 g.Dump(user) 31 } 32 }