我使用json和jQuery從Instagram中提取圖像。通過json與多個陣列循環訪問
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]
- 節點[]是一個數組 - 和我的代碼不通過它不是循環 - 它只是給了我裏面的值節點[]中的第一個對象。如何循環遍歷節點[]以獲取每個對象內部的值thumbnail_src
?
請始終發佈*代碼*如果可以,請勿圖片。 – Jim
我寧願說更好的選擇是使用高級或for循環的對象。 –