保留JSON键值对中值的换行符

pun*_*ish 7 json newline line-breaks

我不确定JSON值中是否允许换行符.我当然无法在JSON中创建以下内容

{"foo": "I am not sure if line breaks are 
         allowed in JSON values. I certainly 
         am unable to create the following in JSON"}
Run Code Online (Sandbox Code Playgroud)

以下肯定不起作用

{"foo": "I am not sure if line breaks are\nallowed in JSON values. I certainly\nam unable to create the following in JSON"}
Run Code Online (Sandbox Code Playgroud)

序言:我想向浏览器或控制台应用程序发送如上所述的长消息,并将其显示为整齐格式,以便用户清晰可读.

Moe*_*eet 0

如果您以 HTML 格式显示它,
那就很简单了。或者在文本区域或其他区域中,尝试用双引号括起来的“\r\n”。双反斜杠是转义的。