我有2个外部的json文件,需要使用键和值来读取这些文件中的数据。我的应用程序不依赖于obj.name等内容。请帮助我打印这些值。
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"
}
这是我正在尝试的代码。
$.ajax({
url:"planets.json",
dataType: "json",
success:function(json){
$.each(json, function(key, value){
console.log(key + ": " + value);
});
}
});
我在控制台中得到了以下输出:
行星:[对象 对象]