Skip to content Skip to sidebar Skip to footer

How Do I Load Every Section Of A Json File That Has Objects Of Objects?

My JSON file looks like the following: [{ 'articles': [ { '1': { 'sections': [ {'1': 'Lots of stuff here.'} ] } }, { '2': { 'sections':

Solution 1:

As you have an array that contains an object that contains the article property that is an array that contains articles, you need to get down to that property to loop through them. Use two properties in the callback function so that you can access the article object:

$.each(d[0].articles, function(i, article) {

As each item is an object that contains a sections property that is an array that contains the sections, you need to get down to that property in each item. Use a different index variable for the sections, so that you still can access the i variable used for the article index:

var mySections = article.sections;
$.each(mySections, function(j, section) {

Inside that loop, j is the index of the section, section is the section string, and i is still then index of the article.

That should get you on the right track with the looping, the rest is mostly just using the right variable for each value.

Post a Comment for "How Do I Load Every Section Of A Json File That Has Objects Of Objects?"