我正在尝试从此https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=-16.516667&lon=-68.166667读取 JSON
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
);
$context = stream_context_create($options);
$data_url = "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=-16.516667&lon=-68.166667";
$json = file_get_contents($data_url,false,$context);
$data = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($data as $key => $val) {
if(is_array($val)) {
echo "$key:\n<br>";
} else {
echo "$key => $val\n<br>";
}
}
这工作正常,但我需要根据键选择特定值,例如:
foreach ($data as $key) {
echo $key["properties"] ["timeseries"] ["0-x"] ["data"] ["instant"] ["details"];
}
但这当然对我不起作用。请问不知道怎么办?谢谢
精慕HU