Can a JSON value contain a multiline string

前端 未结 5 1269
粉色の甜心
粉色の甜心 2020-12-13 16:43

I am writing a JSON file which would be read by a Java program. The fragment is as follows...

{
  \"testCases\" :
  {
    \"case.1\" :
    {
      \"scenario         


        
5条回答
  •  囚心锁ツ
    2020-12-13 17:20

    As I could understand the question is not about how pass a string with control symbols using json but how to store and restore json in file where you can split a string with editor control symbols.

    If you want to store multiline string in a file then your file will not store the valid json object. But if you use your json files in your program only, then you can store the data as you wanted and remove all newlines from file manually each time you load it to your program and then pass to json parser.

    Or, alternatively, which would be better, you can have your json data source files where you edit a sting as you want and then remove all new lines with some utility to the valid json file which your program will use.

提交回复
热议问题