Reputation: 2637
I get this error in the console using JSFiddle and Chrome: http://jsfiddle.net/YdM8n/2/ when trying to parse a Flickr feed with jQuery.
Code:
// a flickr rss feed i am trying to parse.
var yql3 = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fapi.flickr.com%2Fservices%2Ffeeds%2Fphotos_public.gne%3Fid%3D76250020%40N04%26lang%3Den-us%26format%3Drss_200%22&format=json&diagnostics=true&callback=?";
$.getJSON(yql3, function(cbfunc) {
var eachImageArr = $(cbfunc.query.results.rss.channel.item);
$(eachImageArr).each(function() {
$('body').append(this.description);
});
});
Thanks for your help!
Upvotes: 1
Views: 615
Reputation: 50905
If you look at the actual JSON returned, you'd notice the possible format of the description
item can be:
"description": ["html stuff", {some object}]
When looping through every description, you can check to see if it's an array, if and if it is, append the [0]
index to the body. Something like:
var eachImageArr = cbfunc.query.results.rss.channel.item;
$.each(eachImageArr, function() {
if ($.isArray(this.description)) {
$("body").append(this.description[0]);
} else {
$("body").append(this.description);
}
});
But obviously the API needs investigated more to make sure other special cases can't occur...or at least try to account for something similar.
Upvotes: 2
Reputation: 3723
The problem is that in the 18th element of the array, the description is actually an array with the first element being what you expect and the second element being another object.
description: Array[2]
0: " <p><a href="http://www.flickr.com/people/jonathanbell/">jonathanbell.ca</a> posted a photo:</p>↵ ↵<p><a href="http://www.flickr.com/photos/jonathanbell/7290239398/" title="120405_sophia_004"><img src="http://farm8.staticflickr.com/7075/7290239398_3c4b7905da_m.jpg" width="180" height="240" alt="120405_sophia_004" /></a></p>↵↵<p>sophia dishaw</p>"
1: Object
content: "<p>sophia dishaw</p>"
type: "html"
I'm not familiar enough with the flickr api to tell you what the second field is, but it appears to be a name.
Upvotes: 3