簡體   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