我有airport.json文件。這些數據也正是如此,用jquery加載json嵌套對象
{
"diagnostic":{
"status":200,
"elapsetime":"12.9290",
"memoryusage":"15.39MB",
"confirm":"success",
"lang":"id",
"currency":"IDR"
},
"output_type":"json",
"all_airport":{
"airport":[
{
"airport_name":"PATTIMURA",
"airport_code":"AMQ",
"location_name":"Ambon",
"country_id":"id"
},
{
"airport_name":"SOA",
"airport_code":"BJW",
"location_name":"Bajawa",
"country_id":"id"
},
{
"airport_name":"SEPINGGAN",
"airport_code":"BPN",
"location_name":"BalikPapan",
"country_id":"id"
},
{
"airport_name":"SULTAN ISKANDAR MUDA",
"airport_code":"BTJ",
"location_name":"Banda Aceh",
"country_id":"id"
},
{
"airport_name":"HUSEIN SASTRANEGARA",
"airport_code":"BDO",
"location_name":"Bandung",
"country_id":"id"
},
{
"airport_name":"SYAMSUDDIN NOOR",
"airport_code":"BDJ",
"location_name":"Banjarmasin",
"country_id":"id"
},
{
"airport_name":"BLIMBINGSARI",
"airport_code":"DQJ",
"location_name":"Banyuwangi",
"country_id":"id"
},
{
"airport_name":"HANG NADIM",
"airport_code":"BTH",
"location_name":"Batam",
"country_id":"id"
},
{
"airport_name":"BAUBAU",
"airport_code":"BUW",
"location_name":"Baubau",
"country_id":"id"
}
]
}
}
如何獲得「機場」數據,如「AIRPORT_NAME」,「AIRPORT_CODE」,「LOCATION_NAME」等在其陣列機場all_airport對象的哪些價值?
謝謝大家,它完成了。
$.ajax({
url:'airport.json',
dataType: 'json',
success: function(json) {
// get the `airport` array
var airports= json.all_airport.airport;
// loop through the array to populate your list
$.each(airports, function(i, currentAirport) {
// add and option tag to your existing list
$('#yourlist').append(new Option(currentAirport.airport_name));
});
}
});
您正在使用哪種語言?任何代碼嘗試? – Raptor
我'使用JQuery – Beye
你的代碼在哪裏?如果你在Stack Overflow/Google中搜索,你會發現很多使用jQuery解析JSON的例子。 – Raptor