I have 2 external json files, and I have to read data from these files using key and value. my application is independent of obj.name object etc. Please help me print these values.
Planets.json
{
"Planets": [
{ "name": "Mercury",
"color": "Orange",
"distance": "57.91 km",
"radius": "2340 km",
"year": "0.24085 Earth",
"day": "88 days",
"mass": "0.054 Earth"
},
{ "name": "second",
"color": "Orange",
"distance": "57.91 km",
"radius": "2340 km",
"year": "0.24085 Earth",
"day": "88 days",
"mass": "0.054 Earth"
}
}
Airports .json
{
"Airports": [
{
"listing": "East 34th Street Heliport",
"iata": "TSS",
"type": "Heliport",
"size": "Tiny"
}
}
and this is the code I'm trying to do.
$.ajax({
url:"planets.json",
dataType: "json",
success:function(json){
$.each(json, function(key, value){
console.log(key + ": " + value);
});
}
});
and I get it in the console
Planets: [Object Object]
source
share