第一中方法就是自己写转换类
先用SAXReader和Document得到xml格式的数据
@RequestMapping(value = "web_service_url", method = RequestMethod.GET) public String GetAllNotAcceptedCaseList(){ String webServiceUrl=GlobalUtils.getConfig("web_service_url"); //读取配置文件中配置的接口路径,也可直接写死 try { SAXReader reader = new SAXReader(); Document document = reader.read(new URL(webServiceUrl)); // //获取根节点 Element rootElement = document.getRootElement(); Object data =rootElement.getData(); JSONObject jsonObject = xmltoJson(data.toString()); //转成的json数据 System.out.println(jsonObject); } catch (Exception e) { e.printStackTrace(); } return ""; }
转换工具类
/** * 将xml转换为JSON对象 * @param xml xml字符串 * @return * @throws Exception */ public static JSONObject xmltoJson(String xml) throws Exception {