Are multi-line strings allowed in JSON?

前端 未结 9 1472
醉酒成梦
醉酒成梦 2020-11-22 04:21

Is it possible to have multi-line strings in JSON?

It\'s mostly for visual comfort so I suppose I can just turn word wrap on in my editor, but I\'m just kinda curious

9条回答
  •  死守一世寂寞
    2020-11-22 04:34

    Check out the specification! The JSON grammar's char production can take the following values:

    • any-Unicode-character-except-"-or-\-or-control-character
    • \"
    • \\
    • \/
    • \b
    • \f
    • \n
    • \r
    • \t
    • \u four-hex-digits

    Newlines are "control characters" so, no, you may not have a literal newline within your string. However you may encode it using whatever combination of \n and \r you require.

提交回复
热议问题