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

本教程操作环境:Windows10系统、PHP8.1版、DELL G3电脑
PHP把unicode编码的json字符串转中文
json中中文被编码
立即学习“PHP免费学习笔记(深入)”;
$s = '[{"param_name":"email","param_caption":"\u90ae\u7bb1","operator":"\u5305\u542b","value":"aaaa\u5927\u592b\u6492"}]';将中文编码转成中文
Easily find JSON paths within JSON objects using our intuitive Json Path Finder
30
方法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怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号