繁体   English   中英

在蔚蓝液体映射中转义 xml 编码的引号

[英]Escaping xml encoded quotes in azure liquid mapping

我一直在为以下问题苦苦挣扎一段时间。 我有一个 xml,必须使用 azure 上的液体映射将其转换为 json。 有时节点包含 xml 编码的双引号,如下所示:

<node>
    <value>&quot;some string&quot;and the rest</value>
</node>

我的液体贴图如下所示:

"name":"{{ node.value }}"

映射的结果是以下错误:

{
  "Code": "IncorrectLiquidTransformOutputType",
  "Message": "An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: s. Path '[205].node[9].value', line 32305, position 13.'",
  "Details": [
    {
      "Code": "IncorrectLiquidTransformOutputType",
      "Message": "{\"ClassName\":\"Microsoft.Azure.Function.Common.ErrorResponses.ErrorMessageException\",\"Message\":\"An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: s. Path '[205].node[9].name', line ....., position 13.'\",\"Data\":null,\"InnerException\":{\"ClassName\":\"Newtonsoft.Json.JsonReaderException\",\"Message\":\"After parsing a value an unexpected character was encountered: s. Path '[205].node[9].value'....",
      "Details": null,
      "InnerError": null
    }
  ],
  "InnerError": null
}

这意味着字符 " 被正确解码为双引号,然后它会导致 json 出现问题。我需要像这样保留这个字符:

"name":"\"some string\"and the rest"

任何想法如何做到这一点?

您是否尝试在输出中转义它们?

"name":"{{ node.value | 替换:'\\' , '\\' | 替换:'\\"', '\\"'}}"

我遇到了完全相同的问题,但我在通过液体转换之前将 xml 转换为 json。 所以转换得到一个正确转义的 json 字符串:

"name":"William \"Billy\" Bob" 

我测试了上面提出的解决方案(看起来有点奇怪,因为它用相同的值替换了任何出现的情况),起初它没有做任何事情。 然而,经过一番摆弄之后,我删除了第一个 Replace ,然后它实际上起作用了。

{{ node.value | Replace: '\"', '\"'}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM