我正在编写一个可由 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 产生式可以采用以下值:
"
-or-\
-or-control-character\"
\\
\/
\b
\f
\n
\r
\t
\u
四位十六进制数换行符是“控制字符”,所以不,你可能不在你的字符串中有一个文字换行符。但是,您可以使用您需要的 \n
和 \r
的任何组合对其进行编码。
JSONLint工具确认您的 JSON 无效。
而且,如果您想在 JSON 语法中编写换行符而不实际在数据中包含换行符,那么您的运气就更差了。虽然 JSON 在某种程度上旨在对人类友好,但它仍然是数据,您正在尝试对这些数据应用任意格式。这绝对不是 JSON 的意义所在。
https://stackoverflow.com/questions/16690101/