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

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