我想从JSON对象访问某个值。我尝试访问的值是从具有大量嵌套对象和数组的JSON对象启动 - > rocket-> agencies-> abbrev。出于某种原因,我无法访问某个嵌套级别以下的值。以下是控制台中记录的JSON对象的屏幕截图。访问嵌套的JSON值
JSON Object screenshot http://prntscr.com/c6ym11 编辑:Link to the image, since embedding didn't work
Here is a link to an example of the JSON formatting in the returned data
这些都是我已经试过的方法:
data = JSON.parse(data);
var agency = [];
var names = [];
var configuration = [];
for(i = 0; i < data.launches.length; i++){
//This works just fine
names.push(data.launches[i].name);
//This also works
configuration.push(data.launches[i].rocket.configuration);
//This returns undefined
agency.push(data.launches[i].rocket.agencies.abbrev);
//This generates Uncaught TypeError: Cannot read property 'abbrev' of undefined
agency.push(data.launches[i].rocket.agencies[0].abbrev);
}
我可以访问关键:在 “火箭” 的水平值对,但我不能访问嵌套在该级别以下的任何东西。我如何调用数据有什么问题吗?
你的榜样它会工作。所以你最有可能拥有json的一部分,你没有显示哪里代理不在[0]。 https://jsfiddle.net/8oeu7qsm/ – baao