Example:
<?php
$params = '{
"country":"\\u4e2d\\u56fd",
"items0":{
"message":"\\u6211\\u4f1f\\u5927\\u7684\\u7956\\u56fd",
"remark":["\\u6211\\u7231\\u6211\\u7684\u7956\\u56fd"]
},
"items1":{
"message":"\\u6211\\u4f1f\\u5927\\u7684\\u7956\\u56fd",
"remark":["\\u6211\\u7231\\u6211\\u7684\u7956\\u56fd"]
}
}';
function unicodeDecode(&$params){
if(is_array($params)){
foreach ($params as $key => &$value){
$params[$key] = $this->unicodeDecode($value);
}
return $params;
}else{
return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/i', function($match){
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $params);
}
}
$this->unicodeDecode($params);
print_r($params);
本作品採用《CC 協議》,轉載必須註明作者和本文連結