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