1 回答
TA贡献1845条经验 获得超8个赞
查看原始 json 返回,您尝试获取的项目相当隐蔽,但您仍然可以轻松获取它。数据返回示例:
{
"type": "Feature",
"geometry": {
...
},
"properties": {
"meta": {
...
},
"timeseries": [
{
"time": "2020-08-18T12:00:00Z",
"data": {
"instant": {
"details": {
"air_pressure_at_sea_level": 1018.4,
"air_temperature": 4.7,
"cloud_area_fraction": 92.2,
"relative_humidity": 59.3,
"wind_from_direction": 308.4,
"wind_speed": 3.8
}
},
...
您可以通过以下方式访问该特定数据:
$json = file_get_contents($data_url,false,$context);
// This is all you need to turn json into a usable array
$data = json_decode($json,true);
// Loop on the nested timeseries group:
foreach($data['properties']['timeseries'] as $ts) {
// the time part of it
$time = $ts['time'];
// get at it direct
$var = $ts['data']['instant']['details']['air_temperature'];
// shorthand it if you wish:
$details = $ts['data']['instant']['details'];
$var = $details['air_temperature'];
// do whatever else you need to do with it
echo $var;
$array_of_temps[] = $var;
// etc ...
}
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报