The page
attribute is not part of the intended result set you want to retrieve. Try this:
alert(data.results[0].original_title);
Domanda
this is the response string I am trying to iterate through:
{
"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
}
I want to iterate through the results and pull some attribues such as original_title, release_date, etc. I tried using the below code (among others) to try printing one line to no avail:
var data = JSON.parse(this.responseText);
alert(data.page[0].results[0].original_title);
Soluzione
The page
attribute is not part of the intended result set you want to retrieve. Try this:
alert(data.results[0].original_title);
Altri suggerimenti
Remove .page[0]
:
alert(data.results[0].original_title);