【发布时间】:2016-11-24 04:39:48
【问题描述】:
我正在尝试通过从 PHP 中的 JSON 提要中提取这些天气信息来显示它。我不知道为什么它不打印。这是代码:
$url="http://api.openweathermap.org/data/2.5/forecast?q=Albany,usl&APPID=5099c5feb579c7a17b030de0d009282f&units=metric";
$json=file_get_contents($url);
$data=json_decode($json);
echo '<h1>', $data->name, ' (', $data->sys->country, ')</h1>';
// the general information about the weather
echo '<h2>Temperature:</h2>';
echo '<p><strong>Current:</strong> ', $data->main->temp, '° C</p>';
echo '<p><strong>Min:</strong> ', $data->main->temp_min, '° C</p>';
echo '<p><strong>Max:</strong> ', $data->main->temp_max, '° C</p>';
?>
我的输出是这样的:
()
温度:
电流:°C
最低:°C
最高:°C
【问题讨论】:
-
$data=json_decode($json, false);
标签: php json weather-api openweathermap