Convert XML to Json in java
Download Jar : https://www.box.com/s/vm59rumsblk4p25kim8f
Download Jar : https://www.box.com/s/vm59rumsblk4p25kim8f
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
public class xmlToJson {
/**
* @param args
*/
public static void main(String[] args) {
try {
JSONObject jsonObj = null;
jsonObj = XML.toJSONObject("<root><priority value =\"debug\"/><appender-ref ref=\"Log\"/><appender-ref ref=\"stdout\" /> </root>");
String json = jsonObj.toString();
System.out.println("t4acke4 Response is: "+json);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
import org.json.JSONObject;
import org.json.XML;
public class xmlToJson {
/**
* @param args
*/
public static void main(String[] args) {
try {
JSONObject jsonObj = null;
jsonObj = XML.toJSONObject("<root><priority value =\"debug\"/><appender-ref ref=\"Log\"/><appender-ref ref=\"stdout\" /> </root>");
String json = jsonObj.toString();
System.out.println("t4acke4 Response is: "+json);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Tried using this library but got NoSuchMethodError exception for XML.toJsonObject()
ReplyDeleteTry using this:
ReplyDelete@Grab(group='org.json', module='json', version='20090211')