Arrays 为dataweave中的数组添加空检查
我正在将json转换为xml,并且我正在获取一个数组,该数组还有一个内部数组,我无法为内部数组设置null检查,在dataweave中获取脚本错误,我已经附上了示例json请求和xml响应Arrays 为dataweave中的数组添加空检查,arrays,json,xml,mule,dataweave,Arrays,Json,Xml,Mule,Dataweave,我正在将json转换为xml,并且我正在获取一个数组,该数组还有一个内部数组,我无法为内部数组设置null检查,在dataweave中获取脚本错误,我已经附上了示例json请求和xml响应 {"test":[ { "GroupId": "3", "forms": [{ "formId": "2" } ] }, { "
{"test":[ {
"GroupId": "3",
"forms": [{
"formId": "2"
} ]
},
{ "GroupId": "3"
]
} ]}
这是我正在生成的示例xml
<test>
<myforms>
<GroupId>3</GroupId>
<formId>2</formId>
</myforms>
<myforms>
<GroupId>7</GroupId>
<formId>8</formId>
</myforms>
</test>
问题是:-我无法对内部数组进行空检查,即当payload.test.forms=无效的
它正在抛出一个脚本错误,在带有dataweave错误标记的快照下面,请告诉我们如何为内部数组循环设置空检查
这是因为您的语法错误。
您可以尝试一下
default[]
,如下所示:
($.forms default [] map {
formId:$.formId
})
这将有助于获得预期结果请尝试以下代码:-
%dw 1.0
%output application/xml
---
{
test : {
(payload.test map {
myforms : {
GroupId: $.GroupId as :number,
($.forms default [] map {
formId : $.formId
})
}
})
}
}
我已经实现了你的解决方案,但还有一个问题,你可以查看下面的url了解更多详细信息吗?我不确定你是如何映射表单数组的,但你可以试试下面的dw。。或者共享您正在使用的dw您的代码它将更容易理解您是如何映射它的..%dw 1.0%输出应用程序/xml--{test:{(payload.test映射{myforms:{GroupId:$.GroupId as:number,($.forms默认[]映射{formId:$.formId,(rotationid:$.rotationid)当$.rotationid?和$.rotationid!=null}}})}}谢谢你的回复,让我检查一下我已经实现了你的解决方案,但是还有一个问题,你能检查下面的url了解更多详细信息吗
%dw 1.0
%output application/xml
---
{
test : {
(payload.test map {
myforms : {
GroupId: $.GroupId as :number,
($.forms default [] map {
formId : $.formId
})
}
})
}
}