您的位置:首页 > 技术中心 > PHP教程 >

php怎么把json unicode转中文

时间:2023-01-19 09:54

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

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

php怎么把json unicode转中文?

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

json中中文被编码

$s = '[{"param_name":"email","param_caption":"\u90ae\u7bb1","operator":"\u5305\u542b","value":"aaaa\u5927\u592b\u6492"}]';

将中文编码转成中文

方法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视频教程》

以上就是php怎么把json unicode转中文的详细内容,更多请关注gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游