duanpi2033 2016-10-06 17:45
浏览 69
已采纳

在Go / Golang中解组嵌套的JSON数组

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

  • 写回答

2条回答 默认 最新

  • doukuang1897 2016-10-07 00:24
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?