无法使用PHP获取JSON数据

时间:2018-06-15 15:44:06

标签: php json api

我错过了什么或应该这样做吗?

$weatherAPI = "api.openweathermap.org/data/2.5/weather?zip=" . $zipCode . ",us&APPID=myAPI";

$json = file_get_contents($weatherAPI);
$weatherData = json_decode($json,true);

echo $weatherData["main"]["temp"];  

1 个答案:

答案 0 :(得分:3)

至少,您必须使用" http / https"在您的网址中:

$weatherAPI = "http://api.openweathermap.org/data/2.5/weather?zip=" . $zipCode . ",us&APPID=myAPI";

如果您有任何问题,请提供JSON响应和错误。

相关问题