json字符转换成中文方法

 1 public function json_encode($array)
 2     {
 3         $returnStr = '';
 4         $str = @json_encode($array);
 5         if (preg_match_all("/\u[a-z0-9]{4}|[wW]+/U", $str, $matchs)) {
 6             $strArr = array();
 7             foreach ($matchs[0] as $_key => $_val) {
 8                 if (substr($_val, 0, 2) == 'u') {
 9                     $charInt = unpack('n', pack("H4", substr($_val,-4)));
10                     $strArr[$_key] = mb_decode_numericentity('&#'.$charInt[1].';', array(0x80, 0xFFFF, 0, 0xFFFF), 'UTF-8');
11                 } else {
12                     $strArr[$_key] = $_val;
13                 }
14             }
15             $returnStr = implode('', $strArr);
16         } else {
17             $returnStr = $str;
18         }
19 
20         return $returnStr;
21     } 

例:{"data":{"ucode":"test2","sname":"[u4e8cu670d]u5343u53e4u98ceu6d41"}}     => {"data":{"ucode":"test2","sname":"[二服]千古风流"}}
原文地址:https://www.cnblogs.com/duoduoxi/p/5367463.html