标签:
// 返回documentBuilderFactory对象
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// 用documentBuilderFatory对象获得返回documentBuildr对象
DocumentBuilder builder = factory.newDocumentBuilder();
// 得到一个DOM并返回给document对象
Document document = builder.parse(is);
// 得到一个elment根元素
Element element = document.getDocumentElement();
NodeList theNodeList = element.getElementsByTagName("SelectSysResult");
// System.out.println("sss:"+theNode.item(0).getNodeName());
// System.out.println("ssss:"+theNode.item(0).getTextContent());
// 遍历这些子节点
/* for (int i = 0; i < childNodes1.getLength(); i++) {
System.out.println("子节点一层:"+i);
// 获得每个对应位置i的结点
Node node1 = childNodes1.item(i);
if ("soap:Body".equals(node1.getNodeName())) {
NodeList childNodes2 = node1.getChildNodes();
for (int j = 0; j < childNodes2.getLength(); j++) {
System.out.println("子节点二层:"+j);
Node node2 = childNodes2.item(j);
if ("SelectSysResponse".equals(node2.getNodeName())) {
NodeList childNodes3 = node2.getChildNodes();
for (int k = 0; k < childNodes3.getLength(); k++) {
System.out.println("子节点三层:"+k);
Node node3 = childNodes3.item(k);
if ("SelectSysResult".equals(node3.getNodeName())) {
System.out.println("success");
System.out.println(node3.getTextContent());
}
}
}
}
}
}*/
String jsonText = theNodeList.item(0).getTextContent();
jsonText = jsonText.substring(jsonText.indexOf("["), jsonText.lastIndexOf("]")+1 );
JSONArray jsonArr = JSONArray.fromObject(jsonText);
String SysIdArr[] = new String[jsonArr.size()];
for(int i = 0; i < jsonArr.size(); i++){
// if
SysIdArr[i] = jsonArr.getJSONObject(i).getString("_SysId");
System.out.println(SysIdArr[i]);
}
标签:
原文地址:http://www.cnblogs.com/charliewin/p/5054237.html