在为一个旅行支付api工作时,我面临着问题。目的是找到离最近机场的顶级路线。输出是动态JSON数组,其中对象针对每个原始位置进行更改。以下是德里(DEL)
的热门路线示例{
"success":true,
"data": { "BLR": {"origin":"DEL",
"destination":"BLR",
"price":73,
"transfers":0,
"airline":"9W",
"flight_number":809,
"departure_at":"2017-01-16T16:25:00Z",
"return_at":"2017-01-30T11:25:00Z",
"expires_at":"2016-10-11T06:04:57Z"
},
"YTO":{ "origin":"DEL",
"destination":"YTO",
"price":754,
"transfers":1,
"airline":"SV",
"flight_number":765,
"departure_at":"2016-11-04T18:30:00Z",
"return_at":"2016-11-11T14:40:00Z",
"expires_at":"2016-10-13T06:48:37Z"
}
},
"error":null,
"currency":"USD"
}
对于每个原点json数据的变化,所以它们的对象。那么如何提取这种类型的json。致力于PHP。
$jsonurl = "URL";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
$a = $json_output->data->BLR->destination;
echo $a;
这给出了目的地的价值,但问题是我想找到目的地。
答案 0 :(得分:0)
只需循环浏览data
并获取destination
:
foreach($json_output->data as $obj) {
echo $obj->destination;
}