JSON解码中的阿拉伯字符 [英] Arabic Characters in JSON decoding

查看:110
本文介绍了JSON解码中的阿拉伯字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$test = json_encode('بسم الله');
echo $test;

作为此代码的结果,输出为:"\u0628\u0633\u0645 \u0627\u0644\u0644\u0647",而其内容应类似于بسمالله".阿拉伯字符是通过JSON编码而编码的,而在Youtube API上则不是这样: http://gdata.youtube.com/feeds/api/videos/RqMxTnTZeNE? v = 2& alt = json

As a result of this code, the output is: "\u0628\u0633\u0645 \u0627\u0644\u0644\u0647" while it should be something like "بسم الله". Arabic Characters are encoded when being JSON encoded while at the Youtube API this is not the case: http://gdata.youtube.com/feeds/api/videos/RqMxTnTZeNE?v=2&alt=json

您可以在Youtube上看到阿拉伯字符正确显示.我可能会犯什么错误?

You can see at Youtube that Arabic characters are displayed properly. What could be my mistake?

提示:我正在使用API​​<该示例仅是为了澄清.

HINT: I'm working on an API< the example is just for the sake of clarification.

推荐答案

"\u0628\u0633\u0645 \u0627\u0644\u0644\u0647""بسم الله"在JSON中是等效的.

"\u0628\u0633\u0645 \u0627\u0644\u0644\u0647" and "بسم الله" are equivalent in JSON.

PHP仅默认使用Unicode转义,而不是多字节字符的文字.

PHP just defaults to using Unicode escapes instead of literals for multibyte characters.

您可以使用 JSON_UNESCAPED_UNICODE 进行其他指定(前提是您使用的是PHP 5.4或更高版本.

You can specify otherwise with JSON_UNESCAPED_UNICODE (providing you are using PHP 5.4 or later).

json_encode('بسم الله', JSON_UNESCAPED_UNICODE);

这篇关于JSON解码中的阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆