json - JSON 值是否可以包含多行字符串

我正在编写一个可由 Java 程序读取的 JSON 文件。片段如下...

{
  "testCases" :
  {
    "case.1" :
    {
      "scenario" : "this the case 1.",
      "result" : "this is a very long line which is not easily readble.
                  so i would like to write it in multiple lines.
                  but, i do NOT require any new lines in the output.
                  I need to split the string value in this input file only.
                  such that I don't require to slide the horizontal scroll again and again while verifying the correctness of the statements.
                  the prev line, I have shown, without splitting just to give a feel of my problem"
    }
  }
}

最佳答案

根据 the specification ,JSON 语法的 char 产生式可以采用以下值:

  • any-Unicode-character-except-"-or-\-or-control-character
  • \"
  • \\
  • \/
  • \b
  • \f
  • \n
  • \r
  • \t
  • \u 四位十六进制数

换行符是“控制字符”,所以不,你可能在你的字符串中有一个文字换行符。但是,您可以使用您需要的 \n\r 的任何组合对其进行编码。

JSONLint工具确认您的 JSON 无效。


而且,如果您想在 JSON 语法中编写换行符而不实际在数据中包含换行符,那么您的运气就更差了。虽然 JSON 在某种程度上旨在对人类友好,但它仍然是数据,您正在尝试对这些数据应用任意格式。这绝对不是 JSON 的意义所在。

https://stackoverflow.com/questions/16690101/

相关文章:

json - 以友好的方式获取ffmpeg信息

c# - 如何从 JSON 字符串自动生成 C# 类文件

ruby - 如何以正确的格式写入 JSON 文件

c# - 无法使用 Json 序列化 Web API 中的响应

javascript - 将 Javascript 对象编码为 Json 字符串

ruby-on-rails - 将 json 格式的键值对转换为以符号为键的 ruby​​ 哈希的最

javascript - 在 DOM 中嵌入任意 JSON 的最佳实践?

javascript - 将json数据转换为html表

python - Python中的字符串到字典

c# - ASP.Net Core 中的 JSON 序列化/反序列化