github.com/gogf/gf@v1.16.9/.example/container/gtype/json_marshal.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"github.com/gogf/gf/container/gtype"
     7  )
     8  
     9  func main() {
    10  	type Student struct {
    11  		Id     *gtype.Int
    12  		Name   *gtype.String
    13  		Scores *gtype.Interface
    14  	}
    15  	s := Student{
    16  		Id:     gtype.NewInt(1),
    17  		Name:   gtype.NewString("john"),
    18  		Scores: gtype.NewInterface([]int{100, 99, 98}),
    19  	}
    20  	b, _ := json.Marshal(s)
    21  	fmt.Println(string(b))
    22  }