您的位置:58编程 > go struct转json GoFrame gjson-Struct转换

go struct转json GoFrame gjson-Struct转换

2023-04-30 08:33 GoFrame教程

go struct转json GoFrame gjson-Struct转换

go struct转json GoFrame gjson-Struct转换

go struct转json

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.Scan(users); err != nil {
        panic(err)
    }
    fmt.Printf(`%+v`, users)
}

// Output:
// &{Count:1 Array:[John Ming]}


阅读全文
以上是58编程为你收集整理的go struct转json GoFrame gjson-Struct转换全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
© 2024 58编程 58biancheng.com 版权所有 联系我们
桂ICP备12005667号-32 Powered by CMS