1、将字符串转换为Json对象:
String xml_arr =
"<Request service="RoutePushService" lang="zh-CN">
<Body>
<WaybillRoute
id="10049361064088"
mailno="444016153799"
orderid="1559201775741808"
acceptTime="2019-10-18 18:30:00"
acceptAddress="深圳"
remark="快件在【*****营业点】已装车,准备发往 【****集散中心】"
opCode="30"/>
<WaybillRoute
id="10049361064089"
mailno="444016153799"
orderid="1559201775741808"
acceptTime="2019-10-18 18:30:00"
acceptAddress="深圳"
remark="快件到达 【****集散中心】"
opCode="31"/>
</Body>
</Request>"
//将xml转化为JSON对象
JSONObject jsonObject = XML.toJSONObject(xml_arr).getJSONObject("Request");
String jsonStr = jsonObject.get("Body").toString();
//将字符串转换为json数组
com.alibaba.fastjson.JSONArray jsonArray = com.alibaba.fastjson.JSONArray.parseArray(jsonStr);
//将json数组字符串转换成list<Object>
List<WaybillRouteVO> waybillRouteVOList = com.alibaba.fastjson.JSONArray.parseArray(JSONArray.parseArray(jsonStr).toJSONString(),WaybillRouteVO.class);
String xml_obj =
"<Request service="RoutePushService" lang="zh-CN">
<Body>
<WaybillRoute
id="10049361064088"
mailno="444016153799"
orderid="1559201775741808"
acceptTime="2019-10-18 18:30:00"
acceptAddress="深圳"
remark="快件在【*****营业点】已装车,准备发往 【****集散中心】"
opCode="30"/>
</Body>
</Request>"
//将xml转化为JSON对象
JSONObject jsonObject = XML.toJSONObject(xml_arr).getJSONObject("Request");
String jsonStr = jsonObject.get("Body").toString();
//将字符串转换为json对象(用fastjson包)
com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(jsonStr);
//将json对象字符串转化为实体信息
WaybillRouteVO waybillRouteVO = com.alibaba.fastjson.JSONObject.parseObject(com.alibaba.fastjson.JSONObject.parseObject(jsonStr).toString(),WaybillRouteVO.class);