Unmarshall在Go / Golang中嵌套了JSON数组 [英] Unmarshall nested JSON Arrays in Go / Golang

查看:194
本文介绍了Unmarshall在Go / Golang中嵌套了JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有解组嵌套JSON数组的问题。我应该创建什么结构?
我想尽可能避免使用 interface {} ,但我真的不知道在这种情况下是否可能。



Json我想解开:

 [[[{\aaa\\ \\:\aaa\}]]]

和结构我想要使用解开这个:

 类型SomeStructNestedNested结构{
Aaa字符串`json:aaa`
}
类型SomeStructNested结构{
SomeStructNestedNested [] SomeStructNestedNested
}
类型SomeStruct结构{
SomeStructNested [] SomeStructNested
}



链接例如:
https://play.golang.org/p/owuMptNrix

解决方案

是的答案是

  type AutoGenerated [] [] [] struct {
Aaa string`json: aaa`
}

非常感谢您的问题,我在此工具中发现了一个错误将它用于Json与Go的操作,它可以为您节省很多无聊的时间,也可以使用ticks``来表示json字符串,比如 here

Hi I have problem with unmarshalling nested JSON arrays. What struct should I create? I want to avoid using interface{} as much as possible, but I really don't know if it is possible in this case.

Json I want to unmarshall:

"[[[{\"aaa\": \"aaa\"}]]]"

and struct I want to use to unmarshall this:

type SomeStructNestedNested struct {
   Aaa string `json:"aaa"`
}
type SomeStructNested struct {
   SomeStructNestedNested []SomeStructNestedNested
}
type SomeStruct struct {
   SomeStructNested []SomeStructNested
}

Link to example: https://play.golang.org/p/owuMptNrix

解决方案

Yes the answer is just an slice of slices:

type AutoGenerated [][][]struct {
     Aaa string `json:"aaa"`
}

Well thanks to your question I've discovered a bug in this tool I always use it for Json manipulation with Go, it can save you a lot of boring time, also it's better to use ticks `` to represent json strings like here

这篇关于Unmarshall在Go / Golang中嵌套了JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆