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

JSONArray To XML 

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 a JSONArray to XML.

File Name  :  
com/bethecoder/tutorials/json_java/tests/Bean2XML.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.json_java.tests;

import java.util.Arrays;
import java.util.Date;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.XML;

import com.bethecoder.tutorials.json_java.common.Student;

public class Bean2XML {

  /**
   @param args
   @throws JSONException 
   */
  public static void main(String[] argsthrows JSONException {
    Student stud = new Student("Sriram""Kasireddi"2"Singing"new Date(11046));
    Student stud2 = new Student("Sudhakar""Kasireddi"29"Painting"new Date(8286));
    
    JSONArray array = new JSONArray(Arrays.asList(stud, stud2));
    String xml = XML.toString(array, "Student");
    
    System.out.println(xml)//pretty print with indent
  }

}
   

It gives the following output,
File Name  :  OUTPUT


                    Print

   



Books Recommendation

 
 
bl  br