Marshal
package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/v2/frame/g"
)
func main() {
type Student struct {
Id *g.Var
Name *g.Var
Scores *g.Var
}
s := Student{
Id: g.NewVar(1),
Name: g.NewVar("john"),
Scores: g.NewVar([]int{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}
执行后,输出结果:
{"Id":1,"Name":"john","Scores":[100,99,98]}
1 Comment
小陈
看了半天, 感觉gvar组件, 完全可以替代gconv组件, 是不是这样? 有没有什么场景必须要gconv组件的.