【问题标题】:JSON Object to String with carriage-return带回车的 JSON 对象到字符串
【发布时间】:2019-04-27 13:10:45
【问题描述】:

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

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

{"hello:"world1"}

{"hello:"world2"}

{"hello:"world3"}

我用这个:

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

但它返回一个错误,关于不能将对象强制转换为字符串。 我该如何解决这个问题?

【问题讨论】:

    标签: mule tostring dataweave text-indent


    【解决方案1】:

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

    这对我有用,以获得所需的结果:

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

    先写成json,使用writer属性去掉缩进,然后转换成字符串,拼接输出为String application/java

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 2014-03-26
      • 2021-09-04
      • 1970-01-01
      • 2019-01-30
      • 2021-12-31
      • 2011-01-16
      相关资源
      最近更新 更多