JSON规范指出,必须转义的控制字符仅限于U+0000至U+001F的代码:
7. Strings
The representation of strings is similar to conventions used in the C
family of programming languages. A string begins and ends with
quotation marks. All Unicode characters may be placed within the
quotation marks, except for the characters that must be escaped:
quotation mark, reverse solidus, and the control characters (U+0000
through U+001F).
转义的主要目的是在将JSON文档或消息打印到终端或纸张上时,不损坏输出。
但是还有其他控制字符,比如来自C0的[DEL]和来自C1集合(U+0080到U+009F)的其他控制字符。它们在JSON字符串中也应该被转义吗?
String
(一旦使用字符编码解码并取消转义)可以具有任何有限的UTF-16代码单元序列(这就是String
的含义),而与文件编码无关。 - Tom Blodget