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

List to JSON Array 

JSON Simple is a java library for encoding and decoding JSON text. Get the latest binaries from http://code.google.com/p/json-simple/. The following example shows converting a list to JSON Array.

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

import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONValue;

public class List2JsonArray {

  /**
   @param args
   */
  public static void main(String[] args) {

    List list = new ArrayList();
    list.add("one");
    list.add(new Integer(2));
    list.add(new Long(3));
    list.add(new Double(4.26));
    list.add(true);
    list.add(null);
    
    String jsonStr = JSONValue.toJSONString(list);
    System.out.println(jsonStr)
  }

}
   

It gives the following output,
["one",2,3,4.26,true,null]


                    Print

   



Books Recommendation

 
 
bl  br