JSON字符串中是否允许换行?

时间:2015-11-06 11:49:39

标签: json xml soa osb

我需要在我的REST OSB 12c代理的JSON中发送XML,如下所示:

{
    "login": "jstein",
    "identityContext": "jazn.com",
    "taskId": "string",
    "payload": {
        "any_0": {
            "any_01": "<afastamento xmlns:ns1='http: //www.tjsc.jus.br/soa/schemas/comagis/AfastamentoMagistrado' xsi:type='def: AfastamentoMagistradoType' xmlns:xsi='http: //www.w3.org/2001/XMLSchema-instance' xmlns='http: //xmlns.oracle.com/bpel/workflow/task'>
          <ns1:Magistrado>719</ns1:Magistrado>
          <ns1:Status>Inicial</ns1:Status>
          <ns1:Vaga>8770</ns1:Vaga>
          <ns1:Tipo>Licenca Nojo</ns1:Tipo>
          <ns1:PeriodoReferencia/>
          <ns1:DataInicialSolicitada>2015-10-10</ns1:DataInicialSolicitada>
          <ns1:DataFinalSolicitada>2015-11-05</ns1:DataFinalSolicitada>
  </afastamento>"
        }
    },
    "outcome": "Start"
}

OSB 12c向我发回错误:

 "errorMessage" : "ORABPEL-15235\n\nTranslation Failure.\nFailed to translate
 JSON to XML. org.codehaus.jackson.JsonParseException: Illegal unquoted
 character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be
 included in string value\n at [Source: java.io.BufferedReader@7db921c7; line:
 7, column: 619]\nThe incoming data does not conform to the NXSD schema. Please correct the problem.\n"

我在JSONLint上测试我的JSON请求,它总是给我一个关于用<启动一个字符串的错误:

Parse error on line 7:
"any_01": "<afastamento xmlns:
-----------^
Expecting 'STRING, 'NUMBER, 'NULL', 'TRUE', FALSE', '{', '['

1 个答案:

答案 0 :(得分:5)

,文字换行符(CTRL-CHAR, code 10)和换行符是JSON字符串中not allowed的控制字符:

enter image description here

XML不需要元素之间的换行。您可以简单地删除它们,将多行XML文档更改为等效的单行XML文档,该文档可以作为JSON字符串传递而不会出现问题。或者,您可能需要考虑转义换行符\n,或者更一般地说,转义整个字符串:

相关问题