|
@ -357,5 +357,49 @@ public class MqSdkUtil {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 将xml字符串<STRONG>转换</STRONG>为JSON字符串,msg的根节点为row
|
|
|
|
* XML中Msg为数组
|
|
|
|
*
|
|
|
|
* @param xmlString xml字符串
|
|
|
|
* @return JSON<STRONG>对象</STRONG>
|
|
|
|
*/
|
|
|
|
public static String xml2jsonArrayRootRowMS02003(String xmlString) throws Exception {
|
|
|
|
XMLSerializer xmlSerializer = new XMLSerializer();
|
|
|
|
JSON json = xmlSerializer.read(xmlString);
|
|
|
|
Object retInfo= ((JSONObject) json).get("RetInfo");
|
|
|
|
Object retCode= ((JSONObject) retInfo).get("RetCode");
|
|
|
|
if(retCode.equals("1")){
|
|
|
|
//成功
|
|
|
|
Object jsonObject = ((net.sf.json.JSONObject) json).get("MsgInfo");
|
|
|
|
net.sf.json.JSONArray jsonArray1 = new net.sf.json.JSONArray();
|
|
|
|
if (null != jsonObject) {
|
|
|
|
net.sf.json.JSONObject jsonObject1 = (net.sf.json.JSONObject) jsonObject;
|
|
|
|
Object objectMsg=jsonObject1.get("Msg");
|
|
|
|
if(objectMsg instanceof String){
|
|
|
|
JSON jsonsub = xmlSerializer.read(jsonObject1.get("Msg").toString());
|
|
|
|
Object jsonsubBody= ((JSONObject) jsonsub).get("body");
|
|
|
|
jsonArray1.add(jsonsubBody);
|
|
|
|
//重新封装到json中
|
|
|
|
((net.sf.json.JSONObject) json).element("MsgInfo", jsonArray1);
|
|
|
|
}else if(objectMsg instanceof JSONArray){
|
|
|
|
//获取到数组中的CDATA进行再解析
|
|
|
|
net.sf.json.JSONArray jsonArray = (net.sf.json.JSONArray) jsonObject1.get("Msg");
|
|
|
|
for (Object object : jsonArray) {
|
|
|
|
JSON jsonsub = xmlSerializer.read(object.toString());
|
|
|
|
jsonArray1.add(jsonsub);
|
|
|
|
}
|
|
|
|
//重新封装到json中
|
|
|
|
((net.sf.json.JSONObject) json).element("MsgInfo", jsonArray1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}else if(retCode.equals("0")){
|
|
|
|
//重新封装到json中
|
|
|
|
((net.sf.json.JSONObject) json).element("MsgInfo", ((JSONObject) retInfo).get("RetCon"));
|
|
|
|
}
|
|
|
|
return getMsgInfo(json);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|