我需要使用 mirth 连接器将 JSON 文件转换为 CSV。我对 mirth 连接器很陌生,请你帮帮我。
我已经创建了通道,并且我编写了下面的代码,它在单行中给出了我的输出。
代码:
for each (element in jsonObject)
{
var row = <row/>;
var col = <row/>;
for (var key1 in element)
{if (typeof element[key1] != 'object')
{
row[key1] = element[key1].toString();
col[key1] = key1;
}
for (var key2 in element[key1])
{if (typeof element[key1][key2] != 'object')
{
row[key1+key2] = element[key1][key2].toString();
col[key1+key2] = key1+'.'+key2;
}
}
}
msg.appendChild(col);
msg.appendChild(row);
}
输入:
{
"colors": [
{
"color": "black",
"category": "hue",
"type": "primary",
"code": {
"rgba": [255,255,255,1],
"hex": "#000"
}
},
{
"color": "white",
"category": "value",
"code": {
"rgba": [0,0,0,1],
"hex": "#FFF"
}
},
{
"color": "red",
"category": "hue",
"type": "primary",
"code": {
"rgba": [255,0,0,1],
"hex": "#FF0"
}
},
{
"color": "blue",
"category": "hue",
"type": "primary",
"code": {
"rgba": [0,0,255,1],
"hex": "#00F"
}
},
{
"color": "yellow",
"category": "hue",
"type": "primary",
"code": {
"rgba": [255,255,0,1],
"hex": "#FF0"
}
},
{
"color": "green",
"category": "hue",
"type": "secondary",
"code": {
"rgba": [0,255,0,1],
"hex": "#0F0"
}
}
]
}