这是代码:获取特定值
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$url = "http://extreme-ip-lookup.com/json/".$ip;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
$info = curl_exec($curl);
curl_close($curl);
echo $info;
?>
我有这样的输出:
{ "businessName" : "", "businessWebsite" : "", "city" : "Mountain View", "continent" : "North America", "country" : "United States", "countryCode" : "US", "ipName" : "google-public-dns-a.google.com", "ipType" : "Residential", "isp" : "Google", "lat" : "37.3860", "lon" : "-122.0838", "org" : "Google Inc.", "query" : "8.8.8.8", "region" : "California", "status" : "success" } 1
但我需要这个(仅城市或孤立的数值)
Mountain View
$ JSON = json_decode($ info,true); echo $ json ['city']; – mwweb
我尝试使用json_decode,但我的结果是一样的。充分的信息,不只是城市。也许与json_decode服务器问题? 有没有别的办法?没有json_decode? –