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条)

报告相同问题?

悬赏问题

  • ¥100 微信小程序跑脚本授权的问题
  • ¥60 为什么使用python对地震数据进行umap降维后,数据成图会出现不连续的现象
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?