2

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?

4
  • this is incomplete code. are we to infer that xml.responseText is some result of this mysterious jsonFlickrFeed function? Commented Oct 13, 2015 at 16:35
  • @hubsonbropa xml.responseText results in the above jsonFlickrFeed Commented Oct 13, 2015 at 16:37
  • @hubsonbropa The jsonFlickrFeed is what I get when I console.log(xml.responseText)... Wondering how to get specific things within jsonFlickrFeed Commented Oct 14, 2015 at 8:49
  • I'm not following what you mean by 'within'. I assume this function returns a javascript object and that you want to introspect that object. right? Commented Oct 14, 2015 at 16:13

1 Answer 1

1

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)
}
Sign up to request clarification or add additional context in comments.

1 Comment

The jsonFlickrFeed is what I get when I console.log(xml.responseText)... Wondering how to get specific things within jsonFlickrFeed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.