$filename = "http://whois.pconline.com.cn/ipJson.jsp?json=true";
$json = json_decode(file_get_contents($filename));
$city=$json->city;
我这个提不出来
先把获取的内容打印出来 ,看看是不是正常返回的数据
$filename = "http://whois.pconline.com.cn/ipJson.jsp?json=true";也可以根据你的框架功能,写成日志,方便出错时随时检查
另外 ,json_decode 可以接收一个参数来确定解析成对象还是数组
$content = '{"ip":"120.239.177.231","pro":"广东省","proCode":"440000","city":"中山市","cityCode":"442000","region":"","regionCode":"0","addr":"广东省中山市 移通","regionNames":"","err":""}';参考文档:PHP json_decode