使用PHP获取JSON数据时遇到问题

使用PHP获取JSON数据时遇到问题,php,json,api,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"]; 至少,您必须在URL中使用ht

我是不是错过了什么,还是应该这样做

$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"];  

至少,您必须在URL中使用http/https:

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

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

尝试在URL前面添加http://或https://。您是否遇到了特定的错误?尝试回显$json以查看它包含的内容。您当前收到了哪些错误?您可能需要在API调用的前面使用https://。