我有一个JSON响应,我想迭代并捕获事件的值
数字,经度,纬度作为一个组,并将其发送到SMS消息服务。我试过了
不同的方法,但我无法达到这些要素。我试过调试并使用
没有任何运气的不同表达。建议表示赞赏。
[
{
"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>
答案 0 :(得分:1)
使用List<Object>
将json转换为json:json-to-object-transformer
之后。您应该能够使用Mule的任何集合功能,例如foreach
范围/路由器,然后使用MEL表达式来访问特定字段:
<foreach>
<logger level="ERROR" message="#[payload.address]" />
</foreach>
答案 1 :(得分:0)
您还可以使用
将json转换为xml数据 <json:json-to-xml-transformer doc:name="json-to-xml"/>
变换器并在for-each范围内提供xpath表达式,如下所示
<foreach collection="#[xpath('---')]" batchSize="--" doc:name="for-each-account-batch">