php解析json数据
发布网友
发布时间:2022-05-10 02:21
我来回答
共3个回答
热心网友
时间:2022-04-19 19:27
json_encode
对中文的处理是有问题的:
不能处理GBK编码,所有的GBK编码都会替换成空字符;
utf8编码的中文被编码成unicode编码,相当于javascript的escape函数
处理的结果。
为了能正确使用json,首先我们就应该在编码上采用utf8编码,然后再对
json_encode的返回结果稍加处理就可以得到正确的结果了。
即需要加:原始数据$json=iconv("GBK","UTF-8",$json);
json_decode之后需要显示或使用时,再转回来
echo iconv("UTF-8","GBK",$decode['data'][0]['APPName']);
热心网友
时间:2022-04-19 20:45
PHP有提供对JSON的解析支持,可以使用函数:json_decode
$json_string = <<<EOT
{
"status":"Success",
"request":{
"method":"POST",
"parameters":[
{
"name":"email",
"value":"lee.li@fleety.com"
},
{
"name":"apikey",
"value":"ABCDEFG123456"
}
],
"from":"192.168.30.40",
"timestamp":1343285417993
},
"ration":14,
"logon_user":{
"guid":108142,
"email":"lee.li@fleety.com",
"device_number":"UNKNOWN",
"is_male":true,
"role":"USER",
"account_state":"ACTIVE",
"logon_times":19,
"last_logon_time":1343285418001,
"last_logon_by":"EMAIL",
"logon_host":"192.168.30.40",
"logon_token":"43O8NNVC3U8KBI5OT1N07PNZF0C28AGI",
"created_time":1343193738000,
"mobile_phone":"UNKNOWN",
"display_name":"lee.li",
"is_verified":false
}
}
EOT;
$json_object = json_decode($json_string);
echo $json_object->logon_user->guid;
热心网友
时间:2022-04-19 22:19
<?php
$json = '{"APPCount": 2,"data": [
{
"originalID": "991",
"APPName": "优酷",
"APPType": "APK",
"category": "视频",
"versionName": "3.8",
"versionCode": "5",
"packageName ": "cn.dsp.youku",
" APPStatus": "待审核",
"testReportURL": "",
"downloadCount": 0
},
{
"originalID": "992",
"APPName": "优酷",
"APPType": "APK",
"category": "视频",
"versionName": "3.8",
"versionCode": "5",
"packageName ": "cn.dsp.youku",
" APPStatus": "安全测评未通过",
"testReportURL": "http: //192.168.0.106: /SecurityTest/sdsd.pdf",
"downloadCount": 0
}
]
}';
$decode = json_decode($json,true);
echo $decode['data'][1]['testReportURL'];