取来的json数据中文显示 u5fd9u5364u9e25u732bu9225u5b64u5f9d
这是什么编码?
立即学习“Java免费学习笔记(深入)”;
服务端用iconv('GBK', 'UTF-8',$out)不管用,直接取也是乱码,数据库写入用的utf-8
取来的json数据中文显示 u5fd9u5364u9e25u732bu9225u5b64u5f9d
这是什么编码?
立即学习“Java免费学习笔记(深入)”;
服务端用iconv('GBK', 'UTF-8',$out)不管用,直接取也是乱码,数据库写入用的utf-8
u5fd9u5364u9e25u732bu9225u5b64u5f9d是unicode编码
应该是unicode编码,使用unescape解码:
str=" u5fd9u5364u9e25u732bu9225u5b64u5f9d"; unescape(str.replace(/\u/gi, "%u")); " 忙卤鸥猫鈥孤徝"
但是感觉也不像,请确认一下
<?php $a = 'u5fd9u5364u9e25u732bu9225u5b64u5f9d'; echo unicode_decode($a); function unicode_decode($name) { // 转换编码,将Unicode编码转换成可以浏览的utf-8编码 $pattern = '/([w]+)|(\u([w]{4}))/i'; preg_match_all($pattern, $name, $matches); if (!empty($matches)) { $name = ''; for ($j = 0; $j < count($matches[0]); $j++){ $str = $matches[0][$j]; if (strpos($str, '\u') === 0) { $code = base_convert(substr($str, 2, 2), 16, 10); $code2 = base_convert(substr($str, 4), 16, 10); $c = chr($code).chr($code2); $c = iconv('UCS-2', 'UTF-8', $c); $name .= $c; }else{ $name .= $str; } } } return $name; }
PS: 文件保存编码为utf-8.
转换函数取自于: PHP中对汉字进行UNICODE编码和解码的实现
这不是乱码,取出来直接放页面就行
这个不是乱码,是 unicode 编码,PHP 5.4 之后可以直接使用 JSON_UNESCAPED_UNICODE:
$json = json_encode('中文', JSON_UNESCAPED_UNICODE);
被编码了,解码
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号