我正在编写一个JSON文件,该文件将由Java程序读取.片段如下......
{
"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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
Lig*_*ica 55
查看规格!JSON语法的char生成可以采用以下值:
"
-or- \
-or-control-character\"
\\
\/
\b
\f
\n
\r
\t
\u
四十六进制数字换行符是"控制字符",所以不,你的字符串中可能没有文字换行符.然而,你可以使用任何的组合进行编码,\n
并且\r
您需要.
该JSONLint工具确认您的JSON是无效的.
更新:如果你想在你的JSON语法中写入换行符而不在数据中实际包含换行符,那么你甚至会失败.虽然JSON旨在在某种程度上对人类友好,但它仍然是数据,并且您正在尝试对该数据应用任意格式.这绝对不是JSON的意思.
Bri*_*ffe 27
我不确定您的确切要求,但提高"可读性"的一种可能解决方案是将其存储为数组.
{
"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."]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在需要时再次加入
result.join(" ")
Run Code Online (Sandbox Code Playgroud)