将配置的xml指定节点下的数据对应json的子节点数据转成json数组
public static Object constructJSON(String[] singleXmlNodes, JSONObject parentJsonObject,int index) {
boolean isEnd = false;
if(singleXmlNodes.length == (index+1)) {
isEnd = true;
}
if(JSONTools.isJSONObject(parentJsonObject, singleXmlNodes[index])) {
JSONObject jsonObject = parentJsonObject.getJSONObject(singleXmlNodes[index]);
if(jsonObject==null) {
throw new RuntimeException("xml指定节点下无数据");
}
if (!isEnd) {
parentJsonObject.put(singleXmlNodes[index],constructJSON(singleXmlNodes,jsonObject,++index));
}else {
JSONArray jsonArray = new JSONArray();
jsonArray.add(jsonObject);
parentJsonObject.put(singleXmlNodes[index],jsonArray);
}
}else {
JSONArray jsonArray = parentJsonObject.getJSONArray(singleXmlNodes[index]);
if(jsonArray == null ) {
throw new RuntimeException("xml指定节点下无数据");
}
if(!isEnd) {
index++;
for(int i=0; i<jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
jsonArray.remove(i);
jsonArray.add(i,constructJSON(singleXmlNodes, jsonObject, index));
}
parentJsonObject.put(singleXmlNodes[--index], jsonArray);
}
}
return parentJsonObject;
}