github.com/gogf/gf@v1.16.9/.example/container/glist/json_marshal.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "github.com/gogf/gf/container/glist" 7 "github.com/gogf/gf/frame/g" 8 ) 9 10 func main() { 11 type Student struct { 12 Id int 13 Name string 14 Scores *glist.List 15 } 16 s := Student{ 17 Id: 1, 18 Name: "john", 19 Scores: glist.NewFrom(g.Slice{100, 99, 98}), 20 } 21 b, _ := json.Marshal(s) 22 fmt.Println(string(b)) 23 }