需要转义json字符串对象内的花括号吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19878079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:01:52  来源:igfitidea点击:

Do curly braces inside json string objects need to be escaped?

jsonescapingcurly-braces

提问by user1013388

This string is part a JSON object/file:

此字符串是 JSON 对象/文件的一部分:

"Mask" : "{0}(CASE WHEN {1} = {2} THEN {3} ELSE 0 END) {4}"

Will JSON recognize that as part of standard JSON notation or do I need to escape those curly braces s somehow?

JSON 会将其识别为标准 JSON 表示法的一部分,还是我需要以某种方式转义那些花括号?

If so, how does one escape curly braces in JSON?

如果是这样,如何在 JSON 中转义花括号?

回答by Karthik

No. Curly braces do not have to be escaped in JSON.

没有。花括号不必在 JSON 中转义。

回答by Maxim

No, curly braces do not have to be escaped in JSON strings.

不,花括号不必在 JSON 字符串中转义。

JSON is defined in RFC 7159. The Section 7: Stringslists the string characters that mustbe escaped:

JSON 在RFC 7159 中定义。在第7节:字符串列出了字符串中的字符必须进行转义:

All Unicode characters may be placed within the quotation marks, except for the characters that mustbe escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).

所有 Unicode 字符都可以放在引号内,但必须转义的字符除外:引号、反斜线和控制字符(U+0000 到 U+001F)。

While all characters can be escaped, curly braces do not have to be.

虽然所有字符都可以转义,但大括号不是必须的。