Working With The Espn Api,how Can I Parse This Json?
I'm a newbie currently working with the ESPN API, after querying the API I want it to display the headline, link and image for a story. I have only been able to display the headlin
Solution 1:
You've already done most of it in this code:
$.each(data.headlines, function () {
var h2 = $("<h2/>").text(this.headline);
ol.append(h2)
});
this
is a reference to the current object in the headlines
array, and in addition to the headline
property it also has an images
property (which is an array). You just need another nested loop to iterate over that array:
$.each(data.headlines, function () {
var h2 = $("<h2/>").text(this.headline);
ol.append(h2)
$.each(this.images, function() {
// do something with each of the images, using this to refer to it// that's a different this to the one before
});
});
Post a Comment for "Working With The Espn Api,how Can I Parse This Json?"