我得到这样的输出。
[{ “状态”: “成功”, “结果”:{ “BUNDESLAND_NAME”: “莱茵 - 帕拉蒂纳特”, “KREIS_TYP”: “Landkreis”, “GEMEINDE_NAME”: “阿赫”, “GEMEINDE_LAT”:“4978960 ”, “GEMEINDE_LON”: “659052”, “ID_0”: “2”, “ORT_NAME”: “阿赫”, “ORT_LAT”: “4978972”, “ORT_LON”: “659055”, “PLZ”: “54298”} }]
现在我想获得alert(JSON.stringify(ort_list));
的警报值,我怎么能得到它。
答案 0 :(得分:0)
使用此:
var data = [{"status":"success","result":{"BUNDESLAND_NAME":"Rheinland-Pfalz","KREIS_TYP":"Landkreis","GEMEINDE_NAME":"Aach","GEMEINDE_LAT":"4978960","GEMEINDE_LON":"659052","ID_0":"2","ORT_NAME":"Aach","ORT_LAT":"4978972","ORT_LON":"659055","PLZ":"54298"}}];
alert(data[0].result.BUNDESLAND_NAME);
或直接根据您的代码
alert(ort_list[0].result.BUNDESLAND_NAME);
假设
ort_list = [{"status":"success","result":{"BUNDESLAND_NAME":"Rheinland-Pfalz","KREIS_TYP":"Landkreis","GEMEINDE_NAME":"Aach","GEMEINDE_LAT":"4978960","GEMEINDE_LON":"659052","ID_0":"2","ORT_NAME":"Aach","ORT_LAT":"4978972","ORT_LON":"659055","PLZ":"54298"}}];
答案 1 :(得分:0)
<?php
$data='[{"status":"success","result":{"BUNDESLAND_NAME":"Rheinland-Pfalz","KREIS_TYP":"Landkreis","GEMEINDE_NAME":"Aach","GEMEINDE_LAT":"4978960","GEMEINDE_LON":"659052","ID_0":"2","ORT_NAME":"Aach","ORT_LAT":"4978972","ORT_LON":"659055","PLZ":"54298"}}]';
$newData=json_decode($data,true);
echo '<pre>';
print_r($newData);
echo '</br>';
echo 'the field you are looking for is : '.$newData[0]['result']['BUNDESLAND_NAME'];
输出是:
Array
(
[0] => Array
(
[status] => success
[result] => Array
(
[BUNDESLAND_NAME] => Rheinland-Pfalz
[KREIS_TYP] => Landkreis
[GEMEINDE_NAME] => Aach
[GEMEINDE_LAT] => 4978960
[GEMEINDE_LON] => 659052
[ID_0] => 2
[ORT_NAME] => Aach
[ORT_LAT] => 4978972
[ORT_LON] => 659055
[PLZ] => 54298
)
)
)
the field you are looking for is : Rheinland-Pfalz
所以我在这里向您介绍阵列的外观以及我如何访问您想要的特定元素。我希望它清楚。