具有回车符的JSON对象到字符串

问题描述 投票:1回答:1

在我的流程中,我读取并运行(for-each)一组JSON对象。我将每个对象插入APPEND类型的同一文件中。

enter image description here

我想将每个JSONindent存储为false(一行JSON)和carriage-return,如下例所示:

{"hello:"world1"}

{"hello:"world2"}

{"hello:"world3"}

我用这个:

%dw 2.0
 output application/json indent=false
 ---
 payload ++ '\r'

但是它返回一个关于无法将Object强制转换为String的错误。我怎么解决这个问题?

mule tostring dataweave text-indent
1个回答
2
投票

application / json在技术上是一个对象,而不是一个字符串。所以你不能直接连接。

这对我有用,可以获得理想的结果:

%dw 2.0
output application/java
---
write(payload, "application/json", {"indent":false}) as String ++ '\r'

首先写为json使用writer属性删除缩进然后转换为字符串并连接并输出为String application / java

© www.soinside.com 2019 - 2024. All rights reserved.