引入org.json包
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
自己也可以到maven仓库下载jar
maven仓库地址:https://mvnrepository.com/
xlm解析方法
/**
* xml转换为com.alibaba.fastjson.JSONObject
* @param xml
* @return
*/
public static JSONObject xmlToFastJson(String xml){
//将xml转为json
org.json.JSONObject xmlObj = XML.toJSONObject(xml);
JSONObject fastJson = JSONObject.parseObject(xmlObj.toString());
return fastJson;
}