简体   繁体   English

从Javascript中的多维JSON对象检索值

[英]Retrieving values from multidimensional JSON object in Javascript

This is probably a really stupid question, but I'm getting a JSON object returned by an API call and I can't for the life of me figure out how to get the values out of it. 这可能是一个非常愚蠢的问题,但是我正在通过API调用返回一个JSON对象,我一生都无法弄清楚如何从中获取值。 After I make the call, I pretty print the JSON object and it shows the following: 拨打电话后,我很漂亮地打印了JSON对象,它显示以下内容:

 [
  {
    "link_request": {
      "success": true,
      "link": "https://www.blah.com"
    },
    "errors": null
  }
]

I want to be able to get at that link value. 我希望能够获得该链接值。 I've tried both of the following, but neither works. 我已经尝试了以下两种方法,但均无济于事。

var link = data.query.link;

var link = data['query']['link']

Any help? 有什么帮助吗? Thanks! 谢谢!

这里是

obj[0].link_request.link

Use the below code to get link: 使用以下代码获取链接:

jsonArray = [ {
    "link_request": {
      "success": true,
      "link": "https://www.blah.com"
    },
    "errors": null
    }
];
console.log(jsonArray[0].link_request.link)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM