Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mule(Dataweave)将JSON数组转换为字符串_Json_Mule_Dataweave - Fatal编程技术网

Mule(Dataweave)将JSON数组转换为字符串

Mule(Dataweave)将JSON数组转换为字符串,json,mule,dataweave,Json,Mule,Dataweave,这可能很简单,但我在搜索中找到的所有东西都与我的问题有着模糊的联系 我有这个: { "user":"C03999", "caseNumber":"011-1234567", "documents":[ { "file":[ {"name":"indem1","document":"xSFSF%%GSF","mimeType":"PDF"}, {"name":"indem2","document":"xSFSF%%

这可能很简单,但我在搜索中找到的所有东西都与我的问题有着模糊的联系

我有这个:

{
  "user":"C03999",
  "caseNumber":"011-1234567",
  "documents":[
    {
        "file":[
            {"name":"indem1","document":"xSFSF%%GSF","mimeType":"PDF"},
            {"name":"indem2","document":"xSFSF%%GSF","mimeType":"PDF"}
            ]
        }
    ],
  "mortgagee":"22995",
  "billTo":"Originator",
  "agreementDate":"2016-11-25",
  "term":360,
  "expirationDate":"2017-11-25",
  "startDate":"Agreement",
  "lenderEndorsed":true,
  "lenderExecutedAgreement":false,
  "indemnificationAgreementTransferable":false,
  "qadLrsFileNumber":"2016-99999-9999",
  "docketNumber":"2016-9999-99"
}
我想从中提取以下字符串: indem1,indem2

我创建了一个全局函数:

<configuration doc:name="Configuration">
     <expression-language autoResolveVariables="true">
         <global-functions>
             def convertToString(data){
                 return data.toString();
             }
         </global-functions>
     </expression-language>
</configuration>
我的输出如下所示: [indem1\,indem2]


我需要做什么才能得到我想要的字符串(indem1,indem2)?

你的问题标题是“JSON数组到字符串”,但是上面附加的dataweave代码在输出中有application/csv

您正在尝试转换为csv吗??如果这是期望值,则逗号是.csv格式的保留字符,这就是使用反斜杠[indem1\,indem2]进行转义的原因

如果您打算转换为java,下面是返回字符串值的代码

%dw 1.0

%输出应用程序/java
payload.documents[0]。文件。*名称joinBy','

100%正确。我本来打算亲自回来添加解决方案的。这对Dataweave来说是非常新的。结果证明这是一个非常简单的解决方案
%dw 1.0
%output application/csv
---
payload.documents.file map {
      "" : convertToString($.name)
}