How to Convert XML to JSON for Android?

Hello,

Xml data parse by 2 type : 1. SAX Parsing 2.DOM Parsing

But Development in android @ that time Not that use (if you know JSON PARSING)

Use XML to JSON data Convert

Step 1 : Gradle Import


allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }      // add this line
    }
}
-----------------------------------------------------

dependencies {
    compile 'com.github.smart-fun:XmlToJson:1.1.1'    // add this line
}

Step 2: How to Used???

String xml = …; // some xml String

XmlToJson xmlToJson = new XmlToJson.Builder(xml).build();

// convert to a JSONObject
JSONObject jsonObject = xmlToJson.toJson();

// OR convert to a Json String
String jsonString = xmlToJson.toString();

// OR convert to a formatted Json String (with indent & line breaks)
String formatted = xmlToJson.toFormattedString();

Get More Information : https://android-arsenal.com/details/1/4712

Published by

siddharthmakadiya

Computer Engineer Expert in Mobile Application and designer

Leave a comment