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

JSON Array 

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 serializing a simple JSON Array.

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

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonArrayTest {

  /**
   @param args
   @throws JSONException 
   */
  public static void main(String[] argsthrows JSONException {

    JSONArray array = new JSONArray();
    array.put("one");
    array.put("two");
    array.put("three");
    System.out.println(array);
    
    JSONObject obj = new JSONObject();
    obj.put("name""Sriram");
    obj.put("age"2);
    obj.put("hobby""painting");
    array.put(obj);
    System.out.println(array);
  }

}
   

It gives the following output,
[ "one", "two", "three" ]
[ "one", "two", "three", {"age":2,"name":"Sriram","hobby":"painting"} ]



 
  


  
bl  br