Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Struct
转换
Struct
方法用于将整个Json
包含的数据内容转换为指定的数据格式或者对象。
data :=
`
{
"count" : 1,
"array" : ["John", "Ming"]
}`
if j, err := gjson.DecodeToJson(data); err != nil {
panic(err)
} else {
type Users struct {
Count int
Array []string
}
users := new(Users)
if err := j.Struct(users); err != nil {
panic(err)
}
fmt.Printf(`%+v`, users)
}
// Output:
// &{Count:1 Array:[John Ming]}
GetStruct
转换
Get*
方法用于获得指定层级的节点数据,并将该数据转换为指定的结构体对象。Code Block | ||
---|---|---|
| ||
data :=
` |
|
{
|
"count" : 1,
|
"array" : ["John", "Ming"]
|
}`
if j, err := gjson.DecodeToJson(data); err != nil {
panic(err)
} else {
type Users struct {
Count int
Array []string
}
users := new(Users)
if err := j. |
Scan( |
users); err != nil {
panic(err)
}
fmt.Printf(`%+v`, users)
}
// Output:
// &{Count:1 Array:[John Ming]} |
Panel | ||
---|---|---|
| ||
|