Files
gf/geg/util/gconv/gconv_struct5.go

33 lines
506 B
Go
Raw Normal View History

2018-09-30 13:31:03 +08:00
package main
import (
2019-04-03 00:03:46 +08:00
"fmt"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
2018-09-30 13:31:03 +08:00
)
func main() {
2019-04-03 00:03:46 +08:00
type Score struct {
Name string
Result int
}
type User struct {
Scores []Score
}
2018-09-30 13:31:03 +08:00
2019-04-03 00:03:46 +08:00
user := new(User)
scores := map[string]interface{}{
"Scores": map[string]interface{}{
"Name": "john",
"Result": 100,
},
}
2018-09-30 13:31:03 +08:00
2019-04-03 00:03:46 +08:00
// 嵌套struct转换属性为slice类型数值为map类型
if err := gconv.Struct(scores, user); err != nil {
fmt.Println(err)
} else {
g.Dump(user)
}
}