I have a string like this "\u041a\u043b\u0443\u0431 Test";
我有一个像这样的字符串“\ u041a \ u043b \ u0443 \ u0431测试”;
It was decoded by json_encode(), the original string was "Клуб Test" in russian. when I put it to js like
它由json_encode()解码,原始字符串是俄语中的“КлубTest”。当我把它放到js之类的时候
alert("\u041a\u043b\u0443\u0431 Test");
I get correct displaying, like on the screen. So js in some way poperly decodes it to normal view. The question is how can I do the same thing in php, is there any built in method?
我得到正确的显示,就像在屏幕上一样。因此js以某种方式将其正确地解码为普通视图。问题是如何在php中执行相同的操作,是否有内置方法?
THE ANSWER IS: $json_in = '{"testKey":"\u041a\u043b\u0443\u0431 Test"}'; $json_out = json_decode($json_in, true); or Convert "\u041a\u043b\u0443\u0431" to "Клуб" and perform html_entity_decode($str, null, 'UTF-8');
2 个解决方案
#1
1
You probably want HTML entities to print the characters:
您可能希望HTML实体打印字符:
- Ӓ for decimal code
- Ī for hex code
Ӓ代表十进制代码
Ī对于十六进制代码
#2
5
While converting the data, use JSON_UNESCAPED_UNICODE
as the options
转换数据时,请使用JSON_UNESCAPED_UNICODE作为选项
echo json_encode($text, JSON_UNESCAPED_UNICODE);
#1
1
You probably want HTML entities to print the characters:
您可能希望HTML实体打印字符:
- Ӓ for decimal code
- Ī for hex code
Ӓ代表十进制代码
Ī对于十六进制代码
#2
5
While converting the data, use JSON_UNESCAPED_UNICODE
as the options
转换数据时,请使用JSON_UNESCAPED_UNICODE作为选项
echo json_encode($text, JSON_UNESCAPED_UNICODE);