[英]Additional backslash during XML to json conversion in XQuery Marklogic
I'm working with XML to JSON conversion in XQuery for the content with special characters.我正在使用 XQuery 中的 XML 到 JSON 转换来处理带有特殊字符的内容。
XML: <text>$$\parent* \$$</text>
XML:
<text>$$\parent* \$$</text>
Using json:transform-to-json()
with custom config, getting the below result使用
json:transform-to-json()
和自定义配置,得到以下结果
Actual result: { "text": "$$\\parent* \\$$" }
实际结果:
{ "text": "$$\\parent* \\$$" }
Expected result: {"text": "$$\parent* \$$"}
预期结果:
{"text": "$$\parent* \$$"}
I tried multiple ways like using xdmp:quote()
and xdmp:to-json()
methods but not giving the expected result.我尝试了多种方法,例如使用
xdmp:quote()
和xdmp:to-json()
方法,但没有给出预期的结果。
Is there a way to restrict the addition of extra backslash during conversion in XQuery?有没有办法限制在 XQuery 转换期间添加额外的反斜杠?
{"text": "$$\parent* \$$"}
is not valid JSON. {"text": "$$\parent* \$$"}
无效 JSON。
In JSON the \
needs to be escaped as \\
.在 JSON 中,
\
需要转义为\\
。
You can verify that what is currently being produced is valid, and what you are expecting to be validated is invalid by validating them on https://jsonlint.com您可以通过在https://jsonlint.com上验证它们来验证当前生成的内容是否有效,以及您期望验证的内容是否无效
Don't confuse what you see in the JSON value with the data that it represents.不要将您在 JSON 值中看到的内容与其所代表的数据混淆。 The value
$$\parent* \$$
in JSON is $$\\parent* \\$$
, but when you parse/read and ask for the value of text
using APIs, it will return $$\parent* \$$
. JSON 中的值
$$\parent* \$$
是$$\\parent* \\$$
,但是当您使用 API 解析/读取并询问text
的值时,它将返回$$\parent* \$$
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.