81,091
社区成员
发帖
与我相关
我的任务
分享
<?xml version='1.0' encoding='UTF-8'?>
<Response service="RouteService">
<Head>OK</Head>
<Body>
<RouteResponse mailno="**************" orderid="SFKD-**************">
<Route remark="顺丰速运 已收取快件(测试数据)" accept_time="2018-05-01 08:01:44" accept_address="广东省深圳市软件产业基地" opcode="50"/>
<Route remark="已签收,感谢使用顺丰,期待再次为您服务(测试数据)" accept_time="2018-05-02 12:01:44" accept_address="广东省深圳市软件产业基地" opcode="80"/>
</RouteResponse>
</Body>
</Response>
import net.sf.json.xml.XMLSerializer;
public static JSONObject xml2json(String xmlString) {
XMLSerializer xmlSerializer = new XMLSerializer();
JSONObject json = JSONObject.fromObject(xmlSerializer.read(xmlString).toString(1));
return json;
}
JSONObject json = xml2json(xml);
JSONArray jsonArray1 = (JSONArray) json.get("Body");
if (jsonArray1 != null) {
json = jsonArray1.getJSONObject(0);
jsonArray1 = (JSONArray)json.get("Route");
for (int i = 0; i < jsonArray1.size(); i++) {
JSONObject object = (JSONObject) jsonArray1.get(i);
System.out.println("remark:"+object.get("@remark"));
System.out.println("accept_time:"+object.get("@accept_time"));
System.out.println("accept_address:"+object.get("@accept_address"));
System.out.println("opcode:"+object.get("@opcode"));
}
}