Parsing JSON using JQuery Parsing JSON using JQuery json json

Parsing JSON using JQuery


jQuery.each(data.columns, function(i,column) {    jQuery.each(data[column], function(i, row) {    ....    });});


Some comments:

Paolo is right, you can use data[column] to get the list of values:

jQuery.each(data.columns, function(iCol,column) {    jQuery.each(data[column], function(iRow, row) {    ....    });});

Do you need the columns information ? You could get the list of "columns" by iterating directly over data:

for( var column in data ){    jQuery.each(data[column], function(i, row) {    ....    });}

Not really a question but your JSON is not valid JSON, I hope this was only an example and not your real data:

{  "columns"      : ["RULE_ID","COUNTRY_CODE"],  "RULE_ID"      : [1,2,3,7,9,101,102,103,104,105,106,4,5,100,30],   "COUNTRY_CODE" : ["US","US","CA","US","FR","GB","GB","UM","AF","AF","AL","CA","US","US","US"]}


$.getJSON() is asynchronous. You need to supply a callback function to process the result. See the API doc for examples of callback functions.

If you really need your call to be synchronous (it will block the browser while you wait for the result), then you can do this instead:

var url = "week_13.json"var data = jQuery.parseJSON(        jQuery.ajax({            url: url,             async: false,            dataType: 'json'        }).responseText    );