java中xml转json

阅读 125

2023-03-21


public static String xml2jsonString() throws JSONException, IOException {
InputStream in = XmlToJson.class.getResourceAsStream("test.xml");
String xml = IOUtils.toString(in);
JSONObject xmlJSONObj = XML.toJSONObject(xml);
return xmlJSONObj.toString();
}

主要方法:

JSONObject xmlJSONObj = XML.toJSONObject(xml);

 

精彩评论(0)

0 0 举报