这是我试图迭代的响应字符串:
{
"page": 1,
"results": [
{
"adult": false,
"backdrop_path": "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg",
"id": 550,
"original_title": "Fight Club",
"release_date": "1999-10-15",
"poster_path": "/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg",
"popularity": 61151.745000000003,
"title": "Fight Club",
"vote_average": 9.0999999999999996,
"vote_count": 174
},
{
"adult": false,
"backdrop_path": "/5Z0FScA1bB6EbdGmZCUBeUk32eV.jpg",
"id": 14476,
"original_title": "Clubbed",
"release_date": "2008-10-02",
"poster_path": "/bl6PEQtmohEP1zP9srNZY6bXyHg.jpg",
"popularity": 1.7290000000000001,
"title": "Clubbed",
"vote_average": 7.7999999999999998,
"vote_count": 3
},
{
"adult": false,
"backdrop_path": "/qw2Qb42xtyE1B449JoTgb1mVCe1.jpg",
"id": 51021,
"original_title": "Lure: Teen Fight Club",
"release_date": "2010-11-16",
"poster_path": "/aRTX5Y52yGbVL6TGnyI4E8jjtz4.jpg",
"popularity": 0.26600000000000001,
"title": "Lure: Teen Fight Club",
"vote_average": 0.0,
"vote_count": 0
},
{
"adult": false,
"backdrop_path": "/tcoAGvTo96R7Y9ZGVCCz7BZvrvb.jpg",
"id": 104782,
"original_title": "Florence Fight Club",
"release_date": "2010-01-01",
"poster_path": "/eQqqu0srTYcclWqylvgpLyU87hV.jpg",
"popularity": 0.085000000000000006,
"title": "Florence Fight Club",
"vote_average": 0.0,
"vote_count": 0
},
{
"adult": false,
"backdrop_path": null,
"id": 115584,
"original_title": "Fight Club – The “I am Jack’s Laryngitis” Edit",
"release_date": null,
"poster_path": null,
"popularity": 0.059999999999999998,
"title": "Fight Club – The “I am Jack’s Laryngitis” Edit",
"vote_average": 0.0,
"vote_count": 0
}
],
"total_pages": 1,
"total_results": 5
}
我想迭代结果并提取一些属性,例如original_title,release_date等。我尝试使用下面的代码(以及其他代码)尝试打印一行无效:
var data = JSON.parse(this.responseText);
alert(data.page[0].results[0].original_title);
答案 0 :(得分:4)
page
属性不是您要检索的预期结果集的一部分。试试这个:
alert(data.results[0].original_title);
答案 1 :(得分:2)
删除.page[0]
:
alert(data.results[0].original_title);