简体   繁体   English

JSON字符编码与utf8

[英]JSON character encoding vs utf8

我有一个使用JSON字符编码的问题。当我调用ajax并通过json_encode()返回对utf8字符串进行编码时,我的密钥世界是'áo',但是在对其进行编码后返回了'\\ u00c1o',但是在javascript中,jQuery我想将该字符串与'áo'怎么做(我不想将\\ u00c1o与\\ u00c1o进行比较)

An unicode escape sequence is no different than an UTF-8 character (provided your document and JS are served with UTF-8 encoding). Unicode转义序列与UTF-8字符没有什么不同(前提是您的文档和JS使用UTF-8编码提供)。

>>> '\u00c1o' === 'Áo'
<<< true

Note: Strings with different casing are considered different though. 注意:但是,具有不同大小写的字符串被认为是不同的。 You may want to call toLowerCase() or toUpperCase() on both strings for case-insensitive comparison: 您可能希望在两个字符串上都调用toLowerCase()toUpperCase()进行不区分大小写的比较:

>>> '\u00c1o'.toLowerCase() === 'áo'.toLowerCase()
<<< true

The data is interpolated by JS for display and encoded for storage. 数据由JS内插以显示,并进行编码以存储。 Thus, '\Áo' == 'Áo' . 因此, '\Áo' == 'Áo' Note that it does not equal 'áo' , but this does work: 请注意,它不等于'áo' ,但这确实有效:

"áo" == "\u00c1o".toLowerCase()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM