json

json file
Help parse this json . Specifically, you need access to the keys controlworks , courseprojects and so on. I can not fully understand the structure. Please pay attention to the fact that the arrays of 2013-2014, 2014-2015 and so on. not static Ie from the server they can come either 4 or 1, and so on. Below is the code with which I could only dynamically display the name of the arrays '2013-2014' and so on.

 var rnpFilters = JSON.parse(rnpFiltersString); $.each( rnpFilters.rnp, function(key, val) { console.log(key); // 2013-2014, 2014-2015, 2015-2016 }); 
  • one
    it would be possible to attach json himself ...... and who generates such idiotic keys? Like inside this cycle, you can make another cycle using the keys for (i.........i < rnpFilters.rnp[key].length.... - Alex Shimansky
  • @ Alexey Shimansky well, idiotic non-idiots are none of your business. such come back. - Mike Kaharlykskiy
  • mmm .. so you .. clear xD ........ better for dynamic years as keys make a static name. I hope I saw a message about the cycle - Aleksey Shimansky
  • @ Alexey Szymanski, no, not me. what's the difference. I write them to the cycle table and that's all. I don't care what the names of the keys are - Mike Kaharlykskiy
  • @ Alexey Szymanski, I can not. The name of the years is used as a text-Navas tabs. $.each( rnpFilters.rnp, function(key, val) { nextTab = $('#tabs li').length + 1; //create the tab $('<li><a href="#tab'+nextTab+'" data-toggle="tab">'+key+'</a></li>').appendTo('#tabs'); }); - Mike Kaharlykskiy

1 answer 1

If you need to pull out only controlworks

 var rnpFilters = JSON.parse(rnpFiltersString); $.each( rnpFilters.rnp, function(key, val) { for (var i = 0; i < val.length; i++) { console.log(val[i].controlworks); } }); 

If you need to pull out everything

 var rnpFilters = JSON.parse(rnpFiltersString); $.each( rnpFilters.rnp, function(key, val) { for (var i = 0; i < val.length; i++) { for (item in val[i]) { console.log(key + ' ' + item + ' ' + val[i][item]); } } }); 
  • Screen The result is not what was expected) It is necessary to display all fields from all objects of the arrays ('2013-2014 and so on) - Mike Kaharlykskiy
  • @MishaKagarlykskiy updated the answer - Stanislav Grotto
  • Really everything. It was necessary only the final values ​​of the fields. I think I'll figure it out further. Thank you - Mike Kaharlykskiy Nov.
  • one
    @MishaKagarlykskiy "Thank you" to SO is the accepted answer or / and vote for. - Vadim Ovchinnikov
  • 2
    @MishaKagarlykskiy which is the most ridiculous decision in the form of a for (i.........i < rnpFilters.rnp[key].length.... I wrote in my very first comment, (where rnpFilters.rnp[key].length basically is val.length ) but you miraculously decided not to pay attention to this and start offended conversation about the keys .... hospade .... where the world is heading - Alexey Shimansky