{
"Adam":{
"Math":"93",
"Science":"96",
"Email":"[email protected]",
"City":"NY"
},
"Tom":{
"Math":"65",
"Science":"56",
"Email":"[email protected]",
"City":"LA"
},
"Joe":{
"Math":"74",
"Science":"83",
"Email":"[email protected]",
"City":"Washington"
}
}
Above is the JSON content present at the http: //ActualUrl/path.json
I am accessing the JSON file and filling the two arrays with name and marks in science with the code below.
var names=[];
var marks=[];
$.getJSON("http://path.json",function(data){
$.each(data, function(key, val) {
names.push(key);
// I placed alert the check the value key.
marks.push(parseInt(val.Science));
});
});
alert(names.toString()); // names is found blank
alert(marks.toString());
When I check the array at the end. Array is found blank. Why this wrong behaviour with getJSON ? I placed alert in the each and check the value. It returns correct value.