Mule-如何将有效负载转换为json

时间:2016-01-25 09:05:22

标签: json mule

我有这个:

[{"a":"1", "b":"2", "c":"3"}, {"a2":"1", "b2":"2", "c2":"3"}, {"a3":"1", "b3:2", "c3:3"}]

我需要像这样的json输出:

<magento:list-products/>

如何在Mule CE中这样做?有什么建议吗?

编辑:

我从magento <json:object-to-json-transformer doc:name="Object to JSON"/> <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/> 返回数据,并按如下方式转换了有效负载:

<foreach/>

我必须对该有效负载进行一些过滤:使用 <set-variable variableName="productsInfoArr" value="#[flowVars.productsInfoArr.concat(flowVars.productInfo)+',']"/> 并且对于符合我保存在这样的变量中的条件的每个产品:

    $this->db->select('st_student.st_id');
    $this->db->from('st_student'); 
    $this->db->where('st_status',1);
    $this->db->or_where('st_status',2);  
    if(($from!='') && ($to!='')){  
        $this->db->where("ab_date BETWEEN '$from' AND '$to'");
        $this->db->or_where("as_date BETWEEN '$from' AND '$to'");
    } 
    $this->db->group_by('st_student.st_id');    
    $result=$this->db->get();

所以结果如上所述......

基本上问题是:如何使用json项创建数组?

2 个答案:

答案 0 :(得分:1)

我认为你的有效载荷是Java的地图集合。如果是这样,只需使用:

<json:object-to-json-transformer />

答案 1 :(得分:-1)

我通常使用JSONArray来存储JSON对象的列表。在这种情况下,您可能需要通过Expression组件来操作输入:

ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-mingw32]