xml与json互转

依赖包:

<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>

xml转json

XMLSerializer xml = new XMLSerializer(); 

String xmlStr = xml.write(jsonObject); 

System.out.println(xmlStr);  

json转xml

XMLSerializer serializer = new XMLSerializer();
String strjson = serializer.read(result).toString().replace("@", "").trim();
JSONObject resultjson = JSONObject.parseObject(strjson);

原文地址:https://www.cnblogs.com/coderdxj/p/9166066.html