简体   繁体   English

DataWeave 2.0 反斜杠转义

[英]DataWeave 2.0 Backslash escaping

How can you get a single backslash in DataWeave 2.0?如何在 DataWeave 2.0 中获得单个反斜杠?

%dw 2.0
output application/json
---
{
  "attempt1": "\String",
  "attempt2": "\\String"
}

Returns:返回:

{
  "attempt1": "\\String",
  "attempt2": "\\String"
}

Looks like your output is a json and in json the \\ always need to be escaped inside a string.看起来你的输出是一个 json 并且在json中 \\ 总是需要在一个字符串中转义。 That is why you are always going to see two \\这就是为什么你总是会看到两个\\

It appears it will always resolve to an even number if the output is in json like @machaval has said. 如果输出是@machaval所说的json,看来它将始终解析为偶数。

Tweaking mulesoft documentation: https://docs.mulesoft.com/mule-runtime/4.1/dataweave-language-introduction#examples 调整mulesoft文档: https ://docs.mulesoft.com/mule-runtime/4.1/dataweave-language-introduction#examples

%dw 2.0
output application/json
---
{
    "a": "something",
    "b": "dollar sign (\$)",
    "c": 'single quote (\')',
    "c": "double quote (\")",
    "e": 'backtick (`)',
    "f": "backslash(\)",
    "g": "backslashOdd(\\\)",
    "h": "backslashEven(\\\\\\)"
}

produces: 产生:

{
  "a": "something",
  "b": "dollar sign ($)",
  "c": "single quote (')",
  "c": "double quote (\")",
  "e": "backtick (`)",
  "f": "backslash(\\)",
  "g": "backslashOdd(\\)",
  "h": "backslashEven(\\\\)"
}

Favoriting this question in case you get a better answer. 如果您得到更好的答案,请偏爱此问题。 I think I ended up using toString().replace() in the past 我想我最终在过去使用了toString()。replace()

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

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