[英]how to print json array in php?
I have this json array and I want to output particular part in php. 我有这个json数组,我想在php中输出特定的部分。
{ "status": "success", "country": "US", "countryCode": "+1", "regionName": "REGION NAME", "city": "NY" } {“ status”:“成功”,“ country”:“ US”,“ countryCode”:“ + 1”,“ regionName”:“区域名称”,“ city”:“ NY”}
example: 例:
<?php
echo "country: ".[country];
?>
output must be: 输出必须是:
country: US
Use json_decode 使用json_decode
$json = '{
"status": "success",
"country": "US",
"countryCode": "+1",
"regionName": "REGION NAME",
"city": "NY"
}';
$obj = json_decode($json);
print "country: ".$obj->{'country'}; // country: US
You must convert JSON to php array: 您必须将JSON转换为php数组:
$json = '{ "status": "success", "country": "US", "countryCode": "+1", "regionName": "REGION NAME", "city": "NY" }';
$a = json_decode($json,true);
echo "country: ".$a['country'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.