gpt4 book ai didi

javascript - 使用 jquery 加载 json 嵌套对象

转载 作者:行者123 更新时间:2023-11-30 17:45:14 24 4
gpt4 key购买 nike

<分区>

我有 airport.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"
}
]
}
}

如何在 all_airport 对象的机场数组中获取诸如“airport_name”、“airport_code”、“location_name”等“机场”数据?

谢谢大家,搞定了。

$.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 ));
});
}
});

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com