jQuery通过索引为json数据的每个循环

时间:2018-02-01 20:40:03

标签: javascript jquery arrays json

我有一些json数据,id号会改变,所以不是通过ID号引用它,而是想通过数组索引来引用它。

我期待https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Chuck_Schumer_official_photo.jpg/240px-Chuck_Schumer_official_photo.jpg来源,即图片网址{ "batchcomplete":"", "query":{ "normalized":[ { "from":"Chuck_Schumer", "to":"Chuck Schumer" } ], "pages":{ "326708":{ "pageid":326708, "ns":0, "title":"Chuck Schumer", "thumbnail":{ "source":"https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Chuck_Schumer_official_photo.jpg/240px-Chuck_Schumer_official_photo.jpg", "width":240, "height":300 }, "pageimage":"Chuck_Schumer_official_photo.jpg" } } } }

这是json数据的示例:

function processWikiData(wikiData){
  $(wikiData.query).each(function(index, query_item) {
    $(query_item.pages).each(function(index, page_item) {
      // I was hoping to get the array's first index here but clearly this is wrong
      $(page_item.[0]).each(function(index, wiki_id) {
        $(wiki_id.thumbnail).each(function(index, thumbnail_item) {
          alert(thumbnail_item.source);
        });
      });
    });
  });
}

这是我的JavaScript尝试:

{{1}}

0 个答案:

没有答案