依赖包:ora.json maven
代码:
import org.json.JSONObject;
import org.json.XML;
/**********/
String xml = "xml内容";
JSONObject jsonObject = XML.toJSONObject(xml);
System.out.println(jsonObject.toString());
代码:
import org.json.JSONObject;
import org.json.XML;
/*****************/
JSONObject jsonObject = new JSONObject(json);
//头部看需求
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
String Xml = XML.toString(jsonObject);
System.out.println(Xml);