[英]Using json response in PHP
我正在尝试使用我的 json 请求中提供的许多对象中的一个。
试图从给定的数据中仅获取国家/地区名称。
$location = file_get_contents('http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']);
echo $location;
上面的代码给了我以下字符串:
{"ip":"x.xx.xx.x","country_code":"FR","country_name":"France","region_code":"A2","region_name":"Bretagne","city":"Brest","zipcode":"","latitude":xxxx,"longitude":xxxx,"metro_code":"","area_code":""}
任何帮助将不胜感激!
寻找手动json_decode
$tmp = json_decode($location);
echo $tmp->country_code
$a = json_decode($location);
echo $a->country_name;
你可能还想看看这个。 http://www.php.net/manual/en/function.json-decode.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.