public class XmltoJsonUtil {
public static String xml2JSON(String xml) {
JSONObject obj = new JSONObject();
try {
InputStream is = new ByteArrayInputStream(xml.getBytes("utf-8"));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(is);
Element root = doc.getRootElement();
obj.put(root.getName(), iterateElement(root));
return obj.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}