问题描述
DataWeave不喜欢我要用它做的事情,而且我不确定我做错了什么,还是DataWeave的局限性是不可能的.
DataWeave doesn't like what I'm trying to do with it, and I'm not sure if I'm doing something wrong, or if it is a limitation of DataWeave that isn't possible.
在这种情况下:我正在查询Salesforce并获取两个值:让我们将它们称为X和Y.
Here's the scenario: I'm querying Salesforce and getting two values back: lets call them X and Y.
这是我想要的返回[{X:Y}, {X2:Y2}, {X3:Y3}, ...]
,但是,使用DataWeave似乎不可能获得这样的键值对,相反,似乎只能为脚本中的每个值专门设置Key,如下所示:
Here's the return I want [{X:Y}, {X2:Y2}, {X3:Y3}, ...]
however, using DataWeave it doesnt seem possible to get a key value pair like that, instead, it only seems possible to specifically set the Key for each value in the script like so: [{Value_X: X, Value_Y: Y}, {Value_X: X2, Value_Y: Y2}, ...]
这是我当前使用的DataWeave脚本,但是给了我第二个结果:
Here is my current DataWeave script that works, but gives me the second result:
%dw 1.0
%output application/java
---
payload map {
Value_X: $.X,
Value_Y: $.Y
}
这是我希望工作的DataWeave脚本,但没有用
And here's the DataWeave script that I wish worked, but doesn't
%dw 1.0
%output application/java
---
payload map {
$.X: $.Y
}
推荐答案
为使您的Dataweave代码正常工作,您需要用括号将要用作键的变量括起来:
In order for your Dataweave code to work properly, you need to surround the variable you want to use as a key with parentheses:
%dw 1.0
%output application/java
---
payload map {
($.X): $.Y
}
这篇关于DataWeave中的动态键值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!