0
我使用PHP從網站獲取JSON響應,然後使用json_decode
處理響應。這是我的PHP代碼:使用PHP從JSON數據獲取值
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.checkwx.com/taf/LLBG/?format=json");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'X-API-Key: 555555555'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close ($ch);
$json=json_decode($response,true);
$fulltaf = $json['status']['success']['data']['icao'];
這是行不通的。
這是JSON
數據返回給被json_decode
進行處理:
{
"status": "success",
"data": [
{
"icao": "KPIE",
"observed": "07-03-2017 @ 14:20Z",
"raw_text": "KPIE 071353Z 13017G23KT 10SM CLR 21\/13 A3031 RMK AO2 SLP262 T02060128",
"wind_degrees": 130,
}
]
}
的[我如何從JSON中提取數據與PHP?(可能的複製http://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with- PHP) –