【发布时间】:2016-11-25 13:50:00
【问题描述】:
我正在使用 json 和 jQuery 从 Instagram 中提取图片。
json 数据包含对象和数组。不知何故,我无法将第二个数组循环到我需要的值。
这是我的代码:
var request = "./myapi.php?user=jamieoliver"; //&callback=myFunction
$.ajax({
cache: false,
dataType: "json", // or "jsonp" if we enabled it
url: request,
success: function(response) {
console.log(response);
for (var i = 0; i < response.entry_data.ProfilePage.length; i++) {
console.log(response.entry_data.ProfilePage[i].user.media.nodes[i].thumbnail_src);
}
},
error: function(xhr, status, error) {}
});
问题出现在这里:nodes[i] - nodes[] 是一个数组 - 我的代码没有循环遍历它 - 它只给了我在 nodes[] 内的第一个对象内的值。如何循环遍历节点 [] 以便在其每个对象中获取 thumbnail_src 的值?
【问题讨论】:
-
如果可以,请始终发布代码而不是图片。
-
我宁愿说更好的选择是对对象使用高级或 for 循环。