tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 JSON > JSON JAVA > XML To JSONObject

XML To JSONObject 

JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange. Douglas Crockford has provided a reference implementation of JSON in Java at http://json.org/ useful for JSON serialization and deserialization. Click here to download the compiled library. The following example shows converting an XML to JSON object.

File Name  :  
com/bethecoder/tutorials/json_java/tests/XML2Json.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.json_java.tests;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;

public class XML2Json {

  /**
   @param args
   @throws JSONException 
   */
  public static void main(String[] argsthrows JSONException {
    String xml = "<employee><name>ABC</name><age>32</age></employee>";
    JSONObject obj = XML.toJSONObject(xml);
    System.out.println(obj);
  }

}
   

It gives the following output,
{ "employee" : {"age":32, "name":"ABC"} }



 
  


  
bl  br