php怎么将json中的unicode编码转为汉字
程序员文章站
2022-04-13 09:40:58
...
php如何将json中的unicode编码转为汉字?
有两个json数据
$d=[{"_id":{"$id":"4fda7d42741d727c14000000"},"name":"\u519c\u592b\u5c71\u6cc9","bc":"123456","pic":"d: pic\water.jpg","aid":"232fd4df3"}]
$c=[{"_id":{"$id":"4fdaa7f3741d725816000000"},"bc":"012345678","name":"\u7ef4\u8fbe\u7eb8\u5dfe","cls":{"id":"125","name":"\u65e5\u7528\u54c1"},"std":{"name":"\u5f20\u6570","val":"10"}}]
如何将其中unicode字符转为汉字,使得
$d=[{"_id":{"$id":"4fda7d42741d727c14000000"},"name":"农夫山泉","bc":"123456","pic":"d: pic\water.jpg","aid":"232fd4df3"}]
$c=[{"_id":{"$id":"4fdaa7f3741d725816000000"},"bc":"012345678","name":"维达纸巾","cls":{"id":"125","name":"日用品"},"std":{"name":"张数","val":"10"}}]
哪位知道的话帮忙解答一下,先谢谢了~~
------解决方案--------------------
怎么说不行呢
我试了可以,
$str = '$d=[{"_id":{"$id":"4fda7d42741d727c14000000"},"name":"\u519c\u592b\u5c71\u6cc9","bc":"123456","pic":"d: pic\water.jpg","aid":"232fd4df3"}]
$c=[{"_id":{"$id":"4fdaa7f3741d725816000000"},"bc":"012345678","name":"\u7ef4\u8fbe\u7eb8\u5dfe","cls":{"id":"125","name":"\u65e5\u7528\u54c1"},"std":{"name":"\u5f20\u6570","val":"10"}}]';
$str=preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $str);
echo $str;
乱码的话记得换下浏览器编码。
有两个json数据
$d=[{"_id":{"$id":"4fda7d42741d727c14000000"},"name":"\u519c\u592b\u5c71\u6cc9","bc":"123456","pic":"d: pic\water.jpg","aid":"232fd4df3"}]
$c=[{"_id":{"$id":"4fdaa7f3741d725816000000"},"bc":"012345678","name":"\u7ef4\u8fbe\u7eb8\u5dfe","cls":{"id":"125","name":"\u65e5\u7528\u54c1"},"std":{"name":"\u5f20\u6570","val":"10"}}]
如何将其中unicode字符转为汉字,使得
$d=[{"_id":{"$id":"4fda7d42741d727c14000000"},"name":"农夫山泉","bc":"123456","pic":"d: pic\water.jpg","aid":"232fd4df3"}]
$c=[{"_id":{"$id":"4fdaa7f3741d725816000000"},"bc":"012345678","name":"维达纸巾","cls":{"id":"125","name":"日用品"},"std":{"name":"张数","val":"10"}}]
哪位知道的话帮忙解答一下,先谢谢了~~
------解决方案--------------------
怎么说不行呢
我试了可以,
$str = '$d=[{"_id":{"$id":"4fda7d42741d727c14000000"},"name":"\u519c\u592b\u5c71\u6cc9","bc":"123456","pic":"d: pic\water.jpg","aid":"232fd4df3"}]
$c=[{"_id":{"$id":"4fdaa7f3741d725816000000"},"bc":"012345678","name":"\u7ef4\u8fbe\u7eb8\u5dfe","cls":{"id":"125","name":"\u65e5\u7528\u54c1"},"std":{"name":"\u5f20\u6570","val":"10"}}]';
$str=preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $str);
echo $str;
乱码的话记得换下浏览器编码。
相关文章
相关视频
推荐阅读
-
php查询到的数据乱码和转json时中文变成了Unicode的编码怎么解决?
-
php如何将json中的unicode编码转为汉字?
-
php怎么将接受到的字节流转为Unicode编码
-
PHP中json_encode中文被Unicode编码的解决办法
-
php怎么将接受到的字节流转为Unicode编码
-
PHP中对汉字进展UNICODE编码和解码的功能
-
从mysql中取出latin1编码的汉字,输出时显示乱码,php怎么转成utf8格式?
-
从mysql中取出latin1编码的汉字,输出时显示乱码,php怎么转成utf8格式?
-
PHP中对汉字进展UNICODE编码和解码的功能
-
PHP中json_encode中文被Unicode编码的解决办法