Reputation: 3082
Given the below response, how would I get things like title?
jsonFlickrFeed({
"title": "Thing",
"link": "http://www.flickr.com/photos/tags/",
"description": "",
"items": [
{
"title": "Title",
"link": "http://www.flickr.com/photos/123",
"media": {"m":"http://farm6.staticflickr.com/123.jpg"},
},
{
"title": "Title2",
"link": "http://www.flickr.com/photos/1234",
"media": {"m":"http://farm6.staticflickr.com/1234.jpg"},
},
})
I want to do something like:
for (var i=0; i<xml.responseText.length;i++) {
var x = (xml.responseText.items.title[i]);
document.write(x)
}
What am I doing wrong here?
Upvotes: 2
Views: 93
Reputation: 2770
assuming xml.responseText is not null and is the defined result of the function in your question... reference the responseText.items length, not responseText. Then move your index from title to items:
for (var i=0; i < xml.responseText.items.length; i++) {
var x = xml.responseText.items[i].title;
document.write(x)
}
Upvotes: 1