Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON字符串中的控件字符_Json_String_Escaping - Fatal编程技术网

JSON字符串中的控件字符

JSON字符串中的控件字符,json,string,escaping,Json,String,Escaping,必须转义的控制字符的状态仅包含从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 withi

必须转义的控制字符的状态仅包含从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文档或消息时不要损坏输出

但是还有其他的控制字符,比如。它们不应该也在JSON字符串中转义吗?

来自:

在UTF-8中,127以上的所有代码点都以多字节编码。这些字节中大约有一半在C1控制字符范围内。因此,为了避免在UTF-8编码的JSON字符串中包含这些字节,所有这些代码点都需要转义。这有效地消除了UTF-8的使用,JSON字符串也可以用ASCII编码。由于ASCII是UTF-8的一个子集,因此该标准不允许这样做。因此,如果您想将C1控制字符放在字节流中,只需转义它们,但是要求每个JSON表示都使用ASCII在英语环境以外的任何环境中都是非常低效的


UTF-16和UTF-32不可能被使用C1(甚至C0)控制字符的东西解析,因此对于这些编码来说,这一点是没有意义的

转义与字符集编码无关。这与语法有关。
字符串
(一旦文件用字符编码解码并转义为未转义)可以具有任意有限的UTF-16代码单元序列(这就是
字符串
的意思),不管文件编码是什么。@TomBlodget这两个字符串是链接在一起的,因为转义和使用的编码都会影响用于表示JSON字符串的字节。大多数实际使用C1控件的系统要么根本无法处理UTF,要么使用以ESC字节开头的多代码点表示。因此,JSON以UTF格式编码的事实意味着它可以操作的系统可能不关心JSON字符串中出现的C1代码点。
8.  String and Character Issues

8.1.  Character Encoding

   JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32.