2014-09-30 53 views
0

我有一個JSON響應,我想迭代並將事件
數值,經度,緯度作爲一個組捕獲,並將其發送到SMS消息服務。我試過 不同的方法,但我無法獲得這些元素。我試圖調試並使用
不同的表達式,沒有任何運氣。建議表示讚賞。在Mulesoft中迭代JSON列表

[ 
    { 
    "type": " --T::00" 
    }, 
    { 
    "address": "2720 E Madison St", 
    "longitude": "-122.296667", 
    "latitude": "47.623153", 
    "incident_number": "F110104004", 
    "type": "Medic Response", 
    "report_location": { 
    "needs_recoding": false, 
    "longitude": "-122.296667", 
    "latitude": "47.623153" 
    } 
    }, 
{ 
    "address": "2260 1st Av S", 
    "longitude": "-122.334199", 
    "latitude": "47.583347", 
    "incident_number": "F110103709", 
    "type": "Aid Response", 
    "report_location": { 
    "needs_recoding": false, 
    "longitude": "-122.334199", 
    "latitude": "47.583347" 
    } 
}, 
{ 
    "address": "1930 Boren Av", 
    "longitude": "-122.333103", 
    "latitude": "47.617173", 
    "incident_number": "F110103707", 
    "type": "Aid Response", 
    "report_location": { 
    "needs_recoding": false, 
    "longitude": "-122.333103", 
    "latitude": "47.617173" 
} 
] 

這裏是配置文件。

<flow name="seattleemergencyFlow1" doc:name="seattleemergencyFlow1"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8900" path="get-emergency" doc:name="HTTP"/> 
    <http:outbound-endpoint exchange-pattern="request-response" host="data.seattle.gov" port="80" path="resource/kzjm-xkqj.json?" method="GET" contentType="application/json" doc:name="HTTP"/> 
    <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.List"/> 
</flow> 

回答

1

使用json:json-to-object-transformer你有JSON轉換爲List<Object>後。您應該能夠只使用任何的騾子的收藏功能,如foreach範圍/路由器,然後MEL表達式來訪問特定字段:使用

<foreach> 
     <logger level="ERROR" message="#[payload.address]" /> 
</foreach> 
0

也轉換JSON對XML數據

<json:json-to-xml-transformer doc:name="json-to-xml"/>

變壓器並提供換每個範圍的xpath表達式如下

<foreach collection="#[xpath('---')]" batchSize="--" doc:name="for-each-account-batch">