Mulesoft DataWeave:如何为带引号的字符串转义 $

Mulesoft DataWeave: How to escape $ for quoted string

...我正在使用 Anypoint Studio 7.6 并在 DataWeave 2.0 中编写

我找不到在引号字符串中包含 $(美元符号)字符的明确方法。

这是我尝试过的:

%dw 2.0
output application/dw
var sign = "\u0024" // unicode dollar sign
type currency = String {format: "$sign ###.00"} // interpolation from previous var
var cost = 100 as currency
---
{
    directly: "a dollar sign like this: $",
    asdefined: sign,
    indirectly: "This flight, costs $(cost), and is operated by " 
       ++ payload.airline
}

这是我解决问题的方法:

{
  directly: "a dollar sign like this: $",
  asdefined: "$",
  indirectly: "This flight, costs $ 100.00, and is operated by United"
}

我觉得我缺少一些简单的东西。

您好 您所看到的没有问题,只是您使用 application/dw 作为输出。在那种格式中, $ 需要被转义,这就是你看到它的原因。如果您更改为 application/json,它们将消失。

这可能只是因为您的输出是 application/dw。切换到 application/json 或其他 mime-type 后,转义应该可以正常工作。