将字符串转换为整数或数字
Convert the string to integer or number
如何将字符串转换为 transfor dataweave 中的 number/integer。我尝试了以下
%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
"quoteId" : vars.setQuoteOppRecIds.Id,
"productCode" : payload.ServiceTypeCode,
"axSequenceNumber" : vars.counter as :number,
"phaseLevel" : payload.PhaseLevel as :number,
"activeInSOW" : if(payload.PhaseLevelActivateInSOW == "Yes") (toBoolean("true")) else (toBoolean("false")),
"phaseLevelProject" : payload.PhaseLevelProject
}
但我收到类似 Invalid input ':', expected
} or ',' for the object expression. (line 8, column 41):
的错误 我尝试使用 toBoolean 函数将字符串转换为布尔值,它似乎工作正常。谁能告诉我 integer/number conversion
字符串中我缺少的是什么
DW 2 中的转换语法不同。您使用的代码来自 dw 1。在下面的 dw 2 中添加对类型转换的引用,并修复了您的 DW 脚本。
%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
"quoteId" : vars.setQuoteOppRecIds.Id,
"productCode" : payload.ServiceTypeCode,
"axSequenceNumber" : vars.counter as Number,
"phaseLevel" : payload.PhaseLevel as Number,
"activeInSOW" : if(payload.PhaseLevelActivateInSOW == "Yes") (toBoolean("true")) else (toBoolean("false")),
"phaseLevelProject" : payload.PhaseLevelProject
}
如何将字符串转换为 transfor dataweave 中的 number/integer。我尝试了以下
%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
"quoteId" : vars.setQuoteOppRecIds.Id,
"productCode" : payload.ServiceTypeCode,
"axSequenceNumber" : vars.counter as :number,
"phaseLevel" : payload.PhaseLevel as :number,
"activeInSOW" : if(payload.PhaseLevelActivateInSOW == "Yes") (toBoolean("true")) else (toBoolean("false")),
"phaseLevelProject" : payload.PhaseLevelProject
}
但我收到类似 Invalid input ':', expected
} or ',' for the object expression. (line 8, column 41):
的错误 我尝试使用 toBoolean 函数将字符串转换为布尔值,它似乎工作正常。谁能告诉我 integer/number conversion
DW 2 中的转换语法不同。您使用的代码来自 dw 1。在下面的 dw 2 中添加对类型转换的引用,并修复了您的 DW 脚本。
%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
"quoteId" : vars.setQuoteOppRecIds.Id,
"productCode" : payload.ServiceTypeCode,
"axSequenceNumber" : vars.counter as Number,
"phaseLevel" : payload.PhaseLevel as Number,
"activeInSOW" : if(payload.PhaseLevelActivateInSOW == "Yes") (toBoolean("true")) else (toBoolean("false")),
"phaseLevelProject" : payload.PhaseLevelProject
}