gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:42:17 25 4
gpt4 key购买 nike

我正在编写一个可由 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 的意义所在。

关于json - JSON 值是否可以包含多行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16690101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com