[英]Are line feeds allowed in JSON strings?
I need to send XML inside a JSON for my REST OSB 12c Proxy as follow: 我需要在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"
}
The OSB 12c send me back the error: 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"
I am testing my JSON request at JSONLint, and it always gives me the error about start a String with <
: 我正在JSONLint上测试我的JSON请求,它总是给我有关用<
启动字符串的错误:
Parse error on line 7: "any_01": "<afastamento xmlns: -----------^ Expecting 'STRING, 'NUMBER, 'NULL', 'TRUE', FALSE', '{', '['
No , literal line feeds ( CTRL-CHAR, code 10
) and newlines are control characters that are not allowed within a JSON string: 不 ,文字换行符( CTRL-CHAR, code 10
)和换行符是JSON字符串中不允许的控制字符:
XML does not require the line feeds between elements. XML不需要元素之间的换行符。 You can simply remove them, changing your multi-line XML document to an equivalent single-line XML document that will be able to be passed as a JSON string without problem. 您只需删除它们,即可将多行XML文档更改为等效的单行XML文档,该文档将能够毫无问题地作为JSON字符串进行传递。 Or, you may want to consider escaping the line feeds \\n
, or more generally, escaping the entire string: 或者,您可能要考虑对换行符\\n
转义,或更笼统地说,对整个字符串进行转义:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.