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) –