/*获取信息*/ public static List<Map<String, Object>> callPlace() throws IOException { OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/xml"); RequestBody body = RequestBody.create(mediaType, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <soap:Body>" + " <ns:call_Place xmlns:ns= \"http://NurseService.xh.com\">" + " </ns:call_Place>" + " </soap:Body>" + "</soap:Envelope>"); Request request = new Request.Builder() .url("http://" + IniUtil.getConfig().get("ipAddress") + "/PSIM_WS_Maternity/services/NurseService/soap") .post(body) .addHeader("Content-Type", "application/xml") .build(); Response response = client.newCall(request).execute(); String s = new String(response.body().bytes(), "utf-8"); System.out.println(s); InputStream is = new ByteArrayInputStream(s.getBytes("utf-8")); SAXReader reader = new SAXReader(); Document document = null;// 生成XML文档 try { document =reader.read(new BufferedReader(new InputStreamReader(is, "utf-8"))); } catch (DocumentException e) { e.printStackTrace(); } /*解析数组*/ String map = document.getRootElement().elements().get(0).elements().get(0).elements().get(0).getText(); JSONObject jsonObject = JSONObject.parseObject(map); String result = jsonObject.getString("result"); List<Map<String, Object>> mapList = new ArrayList<>(); if ("1".equals(result)) { System.out.println(jsonObject.getString("resultInfo")); String data = jsonObject.getString("data"); List list = JSONObject.parseObject(data, List.class); for (Object o : list) { Map<String, Object> item = (Map) o; //System.out.println(item); mapList.add(item); } } return mapList; }
原文:https://www.cnblogs.com/kkxwze/p/13225008.html