package main
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/v2/container/gtype"
)
func main() {
type Student struct {
Id *gtype.Int
Name *gtype.String
Scores *gtype.Interface
}
s := Student{
Id: gtype.NewInt(1),
Name: gtype.NewString("john"),
Scores: gtype.NewInterface([]int{100, 99, 98}),
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
}
1 Comment
levin
type User struct {
Name string
Profile gtype.String
}
func main() {
hi := &User{
Name: "xiaoming",
Profile: *gtype.NewString(),
}
// hi.Profile.Set("chifan") // success
hi.Profile.Set(`{"avatar":"ddd"}`) // fail
gjson.MustEncode(hi)
}
如果gtype.String里放一段json字符串,尝试序列化会报错