简体   繁体   English

从dataweave转义“ \\”反斜杠以获取csv输出Mule

[英]Escape “\” backslash from dataweave for csv output Mule

CSV output is generated from java Map in Dataweave, Output response adds "\\" to every "," present within the values. CSV输出是从Dataweave中的Java Map生成的,输出响应会将“ \\”添加到值中的每个“,”。 All the map values are added inside the double quotes, ex: map.put('key',"key-Value"); 所有地图值都添加在双引号内,例如:map.put('key',“ key-Value”);

Response Received : 收到回复

Header1, Header2 标题1,标题2

1234,ABC \\,text 1234,ABC \\,文字

7890,XYZ \\,text 7890,XYZ \\,文本

Expected Response : 预期回应

Header1, Header2 标题1,标题2

1234,ABC ,text 1234,ABC,文字

7890,XYZ ,text 7890,XYZ,文本

Header2 should contain "ABC,text" as value without quotes "" Header2应包含“ ABC,text”作为值,且不带引号“”

Tried using %output application/csv escape=" ", but this adds extra space to each blank space in the values ie if the value is "ABC XYZ" then output is "ABC XYZ" (2 spaces in between) 使用%output application / csv escape =“”进行了尝试,但这会在值中的每个空格中添加额外的空间,即,如果值是“ ABC XYZ”,则输出是“ ABC XYZ”(介于2之间)

Any suggestion will be helpful... 任何建议都会有所帮助...

Embedded commas in data in a comma separated value file must be escaped or there is no way to tell those values apart from field separators. 逗号分隔值文件中数据中的嵌入式逗号必须转义,否则除字段分隔符外无法分辨这些值。 If you want some way to have the commas in your CSV file without escaping them, then you need to use a separator other than a comma. 如果您希望以某种方式在逗号分隔的CSV文件中保留逗号,则需要使用逗号以外的分隔符。

You Expected Response as shown would not be valid, as you have a two field header, but data lines that would be interpreted as having 3 fields, not 2 fields, one with an embedded comma which is what the data has and is shown in the Response Received table. 如图所示,您的预期响应将无效,因为您有两个字段标题,但是数据行将被解释为具有3个字段,而不是2个字段,其中一个带有嵌入式逗号,即数据所具有的内容,并显示在响应收到表。

I've got the same scenario, where we have comma in the data itself, like in your case Header2 . 我有同样的情况,在数据本身中有逗号,例如您的Header2。

To solve the issue, I've just added below 为了解决这个问题,我刚刚在下面添加了

%output application/csv quoteValues=true %输出应用程序/ CSV quoteValues = true

above solved my problem, and we got the expected output. 以上解决了我的问题,我们得到了预期的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM