站长资讯网
最全最丰富的资讯网站

php怎么把json unicode转中文

php把json unicode转中文的方法:1、使用“json_encode($log['result_data'],JSON_UNESCAPED_UNICODE);”方法进行转换;2、使用“function unicodeDecode($unicode_str){…}”方法进行转换即可。

php怎么把json unicode转中文

本教程操作环境:Windows10系统、PHP8.1版、DELL G3电脑

php怎么把json unicode转中文?

PHP把unicode编码的json字符串转中文

json中中文被编码

$s = '[{"param_name":"email","param_caption":"u90aeu7bb1","operator":"u5305u542b","value":"aaaau5927u592bu6492"}]';
登录后复制

将中文编码转成中文

方法1.

json_encode($log['result_data'],JSON_UNESCAPED_UNICODE);
登录后复制

方法2.

   /**      * 把unicode编码的字符串转为人眼可看的字符串      * @param $unicode_str      *      * @return string      */     function unicodeDecode($unicode_str){         $unicode_str = str_replace('"', '"', $unicode_str);         $unicode_str = str_replace("'", "'", $unicode_str);         $json = '{"str":"'.$unicode_str.'"}';           $arr = json_decode($json,true);           if(empty($arr)){             return '';         }           return $arr['str'];     }
登录后复制

结果:

[{"param_name":"email","param_caption":"邮箱","operator":"包含","value":"aaaa大夫撒"}]
登录后复制

推荐学习:《PHP视频教程》

赞(0)
分享到: 更多 (0)