大佬教程收集整理的这篇文章主要介绍了将json.Unmarshal嵌套对象转换为字符串或[]字节,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我想得到以下内容:
{ "id" : 15,"foo" : { "foo": 123,"bar": "baz" } }
解散:
type Bar struct { Id int64 `json:"id"` Foo []byte `json:"foo"` }
我收到以下错误:
json: cAnnot unmarshal object into Go value of type []uint8
文件规定:
package main import ( "encoding/json" "fmt" ) var jsonStr = []byte(`{ "id" : 15,"bar": "baz" } }`) type Bar struct { Id int64 `json:"id"` Foo json.Rawmessage `json:"foo"` } func main() { var bar Bar err := json.Unmarshal(jsonStr,&bar) if err != nil { panic(err) } fmt.Printf("%+v\n",bar) }
输出:
以上是大佬教程为你收集整理的将json.Unmarshal嵌套对象转换为字符串或[]字节全部内容,希望文章能够帮你解决将json.Unmarshal嵌套对象转换为字符串或[]字节所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。