我有这个json数组,我想在php中输出特定的部分。
{ “地位”:“成功”, “国家”:“美国”, “countryCode”:“+ 1”, “regionName”:“区域名称”, “城市”:“纽约” }
示例:
<?php
echo "country: ".[country];
?>
输出必须是:
country: US
答案 0 :(得分:0)
$json = '{
"status": "success",
"country": "US",
"countryCode": "+1",
"regionName": "REGION NAME",
"city": "NY"
}';
$obj = json_decode($json);
print "country: ".$obj->{'country'}; // country: US
答案 1 :(得分:0)
您必须将JSON转换为php数组:
$json = '{ "status": "success", "country": "US", "countryCode": "+1", "regionName": "REGION NAME", "city": "NY" }';
$a = json_decode($json,true);
echo "country: ".$a['country'];