Aim: to parse XML to JSON: i have imported json-org.jar to parse XML to JSON. it was fine working with simple java project but during Android its gives ERROR:
String stringxml="<item><title>Clinton slams Russia, China over Syria</title></item>";
JSONObject xmlJSONObj = XML.toJSONObject(stringxml);
org.json.JSONObject j = org.json.XML.toJSONObject(stringxml);
String json = j.toString();
I have got the Error in DDMS: java.lang.NoSuchMethodError:org.json.XML.toJSONObject at org.json.XML.toJSONObject(XML.java:282)
Try something like this
JSONObject jsonObject = null;
FileInputStream is = new FileInputStream("XXX.xml");
StringBuffer buffer = new StringBuffer();
InputStreamReader isr = new InputStreamReader(is, "UTF8");
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
String xml = buffer.toString();
//System.out.println("xml = " + xml);
jsonObject = XML.toJSONObject(xml);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.