修复http请求工具:ContentType为空的情况,修复多层xml解析问题

This commit is contained in:
egzosn@gmail.com
2017-06-23 17:10:17 +08:00
parent 84c3044061
commit d71e7dff12
2 changed files with 34 additions and 5 deletions

View File

@@ -85,12 +85,12 @@ public class XML {
while (it.hasNext()) {
Element e = (Element) it.next();
String k = e.getName();
String v = "";
Object v = "";
List children = e.getChildren();
if (children.isEmpty()) {
v = e.getTextNormalize();
} else {
v = getChildrenText(children);
v = getChildren(children);
}
m.put(k, v);
}
@@ -129,6 +129,32 @@ public class XML {
return sb.toString();
}
/**
* 获取子结点的xml
*
* @param children 集合
* @return String 子结点的xml
*/
public static Object getChildren(List children) {
JSONObject json = new JSONObject();
if (!children.isEmpty()) {
Iterator it = children.iterator();
while (it.hasNext()) {
Element e = (Element) it.next();
String name = e.getName();
String value = e.getTextNormalize();
List list = e.getChildren();
if (!list.isEmpty()) {
json.put(name, getChildren(list));
}else {
json.put(name, value);
}
}
}
return json;
}
/**
* 将请求参数转换为xml格式的string
* @param parameters 请求参数