I have successfully implemented a method to loop through the JSON data provided below:
{"dummmysetsJSONArr":[{"entryID":"1","distance":"100","calories":"50"},{"entryID":"2","distance":"200","calories":"100"},{"entryID":"3","distance":"300","calories":"150"},{"entryID":"4","distance":"400","calories":"200"},{"entryID":"5","distance":"500","calories":"250"},{"entryID":"6","distance":"600","calories":"300"}],"success":1}
This is how I am achieving this:
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
myLogger(jsonarray[key].entryID + " - " + jsonarray[key].distance + " - " + jsonarray[key].calories);
}
}
However, my JSON data seems to be causing an issue with the if check in the for loop.
What might be going wrong with my JSON object?
My intention is to utilize the above for loop to populate data into google.visualization.DataTable() as shown below:
data = new google.visualization.DataTable();
data.addColumn('number', 'distance');
data.addColumn('number', 'calories');
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
//data.addRow(jsonarray[key].distance);
//data.addRow(jsonarray[key].calories);
}
}