json_encode之后的中文会变成'\u4e2d\n\u8d35'这个样子,提供两个函数转换成中文字符。
Python:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
def unicode_convert(t):
2 if t:
3 pattern = re.compile( ' \\\\u[0-9a-f]{4} ')
4 t_all = pattern.findall(t)
5
6 if t_all:
7 for o in t_all:
8 n = unichr(eval( ' 0x '+o.replace( ' \\u ', '')))
9 t = t.replace(o, n)
10 return t
2 if t:
3 pattern = re.compile( ' \\\\u[0-9a-f]{4} ')
4 t_all = pattern.findall(t)
5
6 if t_all:
7 for o in t_all:
8 n = unichr(eval( ' 0x '+o.replace( ' \\u ', '')))
9 t = t.replace(o, n)
10 return t
PHP:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
function unicode_convert(
$t) {
2 preg_match_all('/\\\\u[0-9a-f]{4}/', $t, $t_all);
3
4 foreach ( $t_all[0] as $ch) {
5 $_ch = intval( str_replace('\u', '0x', $ch), 16);
6 $uni_ch = mb_convert_encoding('' . $_ch . ';', 'UTF-8', 'HTML-ENTITIES');
7 $t = str_replace( $ch, $uni_ch, $t);
8 }
9
10 return $t;
11 }
2 preg_match_all('/\\\\u[0-9a-f]{4}/', $t, $t_all);
3
4 foreach ( $t_all[0] as $ch) {
5 $_ch = intval( str_replace('\u', '0x', $ch), 16);
6 $uni_ch = mb_convert_encoding('' . $_ch . ';', 'UTF-8', 'HTML-ENTITIES');
7 $t = str_replace( $ch, $uni_ch, $t);
8 }
9
10 return $t;
11 }