在从 dataweave 2 mule 中的变量中检索值时,raw 不起作用

问题描述 投票:0回答:1

我只是想将数值转换为字符串而不丢失它们的小数值,包括零。

这可以使用 DataWeave 2.0 中的原始运算符来完成。在下面,我将 123.0 数值转换为 "123.0" 字符串值。

但是当我使用 mule 变量尝试相同的操作时,表达式会抛出一个错误,例如“无法将 Null 强制转换为字符串”。

我在 DataWeave 2.0 中尝试使用原始运算符作为变量的代码。

%dw 2.0
output application/json
var inputValue = payload.message
---
inputValue.^raw as String

关于如何在变量上使用原始运算符或如何将数值转换为字符串而不丢失十进制值,有什么想法吗?

例如:123.0 到“123.0”、123.00 到“123.00”、123.63 到“123.63”

dataweave mulesoft mule4
1个回答
0
投票

您可以尝试使用substring模块

%dw 2.0
output application/json
import * from dw::core::Strings
var inputValue = payload.^raw
---
substringBefore(substringAfter(inputValue,":"),"\n")

输入 123.0 -> 输出“123.0”

输入 123.00 -> 输出“123.00”

输入 123.63 -> 输出“123.63”

© www.soinside.com 2019 - 2024. All rights reserved.