【发布时间】:2014-11-30 09:36:42
【问题描述】:
我正在进行网络服务调用并检索 json 有效负载:
[
{
"type": " --T::00"
},
{
"address": "10049 College Way N",
"longitude": "-122.335022",
"latitude": "47.701756",
"incident_number": "F110104009",
"type": "Aid Response",
"report_location": {
"needs_recoding": false,
"longitude": "-122.335022",
"latitude": "47.701756"
}
},
{
"address": "5929 Beach Dr Sw",
"longitude": "-122.397816",
"latitude": "47.550431",
"incident_number": "F110104008",
"type": "Aid Response",
"report_location": {
"needs_recoding": false,
"longitude": "-122.397816",
"latitude": "47.550431"
}
}
我正在遍历每一行并将键值提取到 MySQl DB 表中。我希望插入第一个值“type -t00”,事件编号、经度、纬度为空白。但是,在随后的每次迭代中,我都希望摄取能够正常工作。相反,我得到以下信息:
ID Longitude Latitude incident_number type
1 null null null --T::00
65 null null null 1RED 1 Unit
70 null null null 1RED 1 Unit
313 null null null 1RED 1 Unit
314 null null null 1RED 1 Unit
315 null null null 1RED 1 Unit
316 null null null 1RED 1 Unit
发生的情况是只有类型从 JSON 有效负载中正确摄取,但其他所有有效负载值均为空。当我调试时,我确实看到了迭代并且可以清楚地识别payload.incident_number、payload.longitude,但在我看来,问题已经被吸收了。我尝试只摄取 event_number,但它在表中显示为 null。
非常感谢任何帮助。
下面是我的configuration.xml:
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="demo"
password="Welcome1" database="demo" doc:name="MySQL Configuration"/>
<flow name="seattleemergencyFlow1" doc:name="seattleemergencyFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8900"
path="get-emergency" doc:name="HTTP"></http:inbound-endpoint>
<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"></http:outbound-endpoint>
<json:json-to-object-transformer returnClass="java.util.List" doc:name="JSON to Object">
</json:json-to-object-transformer>
<foreach doc:name="For Each">
<db:insert config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[INSERT INTO emergencyrecords
(incident_number, type, longitude)
VALUES
(
#[payload.incident_number],
#[payload.type],
#[payload.longitude])]]></db:parameterized-query>
</db:insert>
</foreach>
</flow>
</mule>
【问题讨论】:
-
对不起大卫..刚学习论坛。我已经完成了我之前的问题。感谢您的帮助。