如何在php中打印json数组


how to print json array in php?

我有这个json数组,我想用php输出特定的部分。

{"状态":"成功","country":"US","countryCode":"+1","regionName":"REGION NAME","城市":"纽约"}

示例:

<?php
  echo "country: ".[country];
?>

输出必须为:

country: US

使用json_decode

$json = '{ 
"status": "success", 
"country": "US", 
"countryCode": "+1",   
"regionName": "REGION NAME", 
"city": "NY" 
}';
$obj = json_decode($json);
print "country: ".$obj->{'country'}; // country: US

您必须将JSON转换为php数组:

$json = '{ "status": "success", "country": "US", "countryCode": "+1", "regionName": "REGION NAME", "city": "NY" }';
$a = json_decode($json,true);
echo "country: ".$a['country'];