2014-03-26 3 views
0

다음 JSON 문서에서 줄 바꿈 문자를 어떻게 피할 수 있습니까? 현재 문서 유효성 검사에 실패합니다.JSON 문서 이스케이프 문자

{ 
    "questionId" : 1, 
    "text" : "Given the following code, what gets printed?", 
    "questype" : "RADIO_BUTTON", 
    "issourcecode" : true, 
    "sourcecode" : "def patternMatcher(list: List[Int]) = list match { \\n\\n 
         case Nil => \"The List is empty\" \n 
         case x :: Nil => s\"The List contained $x\" \n 
         case x :: xss => s\"The List contained $x and $xss\" \n 
         case _ => \"None of the above\" \n 
        } 
        patternMatcher(List(1,2,3,4)) -- What gets printed here?", 
    "examId" : 1000, 
    "answers" : [ 
     { 
      "id" : 1, 
      "text" : "The List is empty", 
      "isCorrectAnswer" : false 
     }, 
     { 
      "id" : 2, 
      "text" : "The List contained 1", 
      "isCorrectAnswer" : false 
     }, 
     { 
      "id" : 3, 
      "text" : "The List contained 1 and List(2,3,4)", 
      "isCorrectAnswer" : true 
     }, 
     { 
      "id" : 4, 
      "text" : "None of the above", 
      "isCorrectAnswer" : false 
     } 
    ] 
} 

줄 바꿈 문자가있는 행 6에서 오류가 발생합니다!

{ 
    "questionId" : 1, 
    "text" : "Given the following code, what gets printed?", 
    "questype" : "RADIO_BUTTON", 
    "issourcecode" : true, 
    "sourcecode" : "def patternMatcher(list: List[Int]) = list match {\\n 
         case Nil => \"The List is empty\" \\n 
         case x :: Nil => s\"The List contained $x\" \\n 
         case x :: xss => s\"The List contained $x and $xss\" \\n 
         case _ => \"None of the above\" \\n 
        } 
        patternMatcher(List(1,2,3,4)) -- What gets printed here?", 
    "examId" : 1000, 
    "answers" : [ 
     { 
      "id" : 1, 
      "text" : "The List is empty", 
      "isCorrectAnswer" : false 
     }, 
     { 
      "id" : 2, 
      "text" : "The List contained 1", 
      "isCorrectAnswer" : false 
     }, 
     { 
      "id" : 3, 
      "text" : "The List contained 1 and List(2,3,4)", 
      "isCorrectAnswer" : true 
     }, 
     { 
      "id" : 4, 
      "text" : "None of the above", 
      "isCorrectAnswer" : false 
     } 
    ] 
} 

내가 내 JSON을 확인하려면 다음 웹 사이트를 사용하고 항상 다음과 같은 오류와 함께 실패합니다 :

http://www.freeformatter.com/json-validator.html

The JSON input is NOT valid in JavaScript, unterminated string literal (At line #6), (At position #73) 
+1

도움이 될 수 있습니다. http://stackoverflow.com/a/4253415/1324816 – user6123723

답변

0

는 나중에 다음에 JSON을 변경 승인! 다음을 반영하도록 변경하자마자 작동했습니다.

"sourcecode" : "def patternMatcher(list: List[Int]) = list match {\\n case Nil => \"The List is empty\" \\n case x :: Nil => s\"The List contained $x\" \\n case x :: xss => s\"The List contained $x and $xss\" \\n case _ => \"None of the above\" \\n}patternMatcher(List(1,2,3,4)) -- What gets printed here?" 

나는 한 줄로 입력해야했습니다. 이상한!