Mulesoft DataWeave:如何对引用的字符串进行转义

问题描述

...我正在使用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: "\$",costs \$ 100.00,and is operated by United"
}

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

解决方法

嗨,您所看到的没有问题,只是您使用application / dw作为输出。需要以这种格式$进行转义,这就是为什么您会看到它的原因。如果更改为application/json,它们将会消失。

,

这可能仅仅是因为您的输出是application / dw。切换到application / json或其他mime类型后,转义应该正确进行。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...