PHP的json_encode是否保证产生ASCII字符串? [英] Is PHP's json_encode guaranteed to produce ASCII string?

查看:121
本文介绍了PHP的json_encode是否保证产生ASCII字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,受试者说了所有的话.我正在使用json_encode将一些UTF8数据转换为JSON,我需要将其传输到当前仅ASCII的某个层.因此,我想知道是否需要使它成为UTF-8意识,还是可以让它保持原样.

Well, the subject says everything. I'm using json_encode to convert some UTF8 data to JSON and I need to transfer it to some layer that is currently ASCII-only. So I wonder whether I need to make it UTF-8 aware, or can I leave it as it is.

从JSON rfc来看,UTF8在JSON输出中也是有效的字符集,尽管不建议这样做,即某些实现可以将UTF8数据保留在其中.问题是PHP的实现是将所有内容都以ASCII格式转储还是选择以UTF-8格式保留.

Looking at JSON rfc, UTF8 is also valid charset in JSON output, although not recommended, i.e. some implemenatations can leave UTF8 data inside. The question is whether PHP's implementation dumps everthing as ASCII or opts to leave something as UTF-8.

推荐答案

其他语言中的JSON支持不同json_encode()无法生成除ASCII以外的其他任何内容.

Unlike JSON support in other languages, json_encode() does not have the ability to generate anything other than ASCII.

这篇关于PHP的json_encode是否保证产生ASCII字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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