【发布时间】:2019-02-04 05:26:14
【问题描述】:
【问题讨论】:
-
为了以后参考,代码不要用图片,用文字。为什么不上传图片:meta.stackoverflow.com/questions/285551/…
标签: mule mule-studio mule-el mule-esb mule-cluster
【问题讨论】:
标签: mule mule-studio mule-el mule-esb mule-cluster
这是因为您将空白字符串分配给 dValue.doctorId 而不是 (doctorId)。同样使用default 在这里设置默认值更容易。这是一个例子:
%dw 2.0
output application/xml
var doctorInformationList=[{doctorId: '1'},{doctorId: '2'}, {}]
---
root: {
DoctorInformationList: doctorInformationList map ((dValue, dIndex) ->
doctorId : dValue.doctorId default ""
)
}
【讨论】:
最好使用when - otherwise。
以下是针对您的问题的数据编织转换
%dw 2.0
%output application/json
%var doctorInfoList=[{doctorId: '1', doctorName : 'A'},{doctorId: '2', doctorName : 'B'},
{doctorId: null, doctorName : 'C'},{doctorId: '', doctorName : 'D'},{}]
---
{
DoctorInfoList: doctorInfoList map ((doctorValue, doctorIndex) -> {
"docorId" : '' when doctorValue.doctorId is :null otherwise doctorValue.doctorId,
"docorName" : doctorValue.doctorName
}
)
}
输出如下:
{
"DoctorInfoList": [
{
"docorId": "1",
"docorName": "A"
},
{
"docorId": "2",
"docorName": "B"
},
{
"docorId": "",
"docorName": "C"
},
{
"docorId": "",
"docorName": "D"
},
{
"docorId": "",
"docorName": null
}
]
}
将doctorInfoList 替换为您的payload
【讨论】:
%output 和 %var 也是 output 和 var。 :null 应该是 Null。