duannao8450
2018-06-29 23:37
浏览 467
已采纳

如何在Golang中获取JSON唯一字段的名称和深度嵌套的子字段的值?

I have a json file that looks like this

{
  "links": {
    "uniqueurl_1": {
      "a": {
        "b": [
          "stuff"
        ],
        "I": {
          "want": {
            "to": "morestuff",
            "go": {
              "in": {
                "here": {
                  "and": "array",
                  "itis": {
                    "very": "string",
                    "deep": "stringIwant"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

And I want to get the uniqueurl_1 (that is always different for each link), and I also want to get the "deep" field's value ("stringIwant")

I know if it's not too deeply nested, you can just create a bunch of structs in Golang, but when it's this deep would it still be the only/best way to do it?

图片转代码服务由CSDN问答提供 功能建议

我有一个看起来像这样的json文件

  {  
“链接”:{
“ uniqueurl_1”:{
“ a”:{
“ b”:[
“东西” 
],
“ I”:{
“想要”:  {
“ to”:“ morestuff”,
“ go”:{
“ in”:{
“ here”:{
“ and”:“ array”,
“ itis”:{\  n“非常”:“字符串”,
“深”:“ stringIwant” 
} 
} 
} 
} 
} 
} 
} 
} 
} 
} 
    
 
 

,我想获取 uniqueurl_1 (每个链接总是不同的),并且我还想获​​取“深”字段的 值(“ stringIwant”)

我知道它嵌套的不是很深,您可以在Golang中创建一堆结构,但是当深度很深时,它仍然是唯一/最好的 这样做吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题