Using this code:
$.each(data.toptracks.track, function(index, item){
$('.lastfm').append('<figure class="clearfix"><p><a href="'+item.url+'">'+item.name+'</a>'+item.artist.name+'</p><div class="vinyl"><img class="recordLabel" src="' + item.image[3]['#text'] + '" /></div></figure>');
});
use this URL to view JSON:
For some reason only the first iteration(?) gets output!
jSFiddle link: http://jsfiddle.net/MS3Gu/
Probably because on the second iteration, the
itemdoes not have animageproperty, soitem.image[3]['#text']will cause it to crash.Since there’s no
imageproperty, when you doitem.imageit returnsundefined, soitem.image[3]is attempting to look up the3property onundefined.To remedy it, you can test each level of depth to make sure properties exist.