在PHP中访问JSON数据的正确方法

时间:2017-10-17 23:47:09

标签: php json response

我有这个简单的语句来调用JSON响应。它一直工作到最近我发现它停止工作。不知道为什么它不起作用。这是我的代码。它非常简单。

//Here is the response from the API
{"country":"US","state":"NY","city":"GLEN COVE"} 

$zip = "11542";
$url = "http://ziptasticapi.com/".$zip;
$info = file_get_contents($url);
$info = json_decode($info);

$cityname = $info->city;
$statename = $info->state;

不确定为什么它最终没有拿起数据。我甚至尝试将其更改为json_decode($ info,true)并将其更改为$ info ['city']。

0 个答案:

没有答案