4:14 am - Thursday July 19, 2018

Example program in JSONArray using List

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                                         This program explains about the concept of JSONArray using List  and in addition output has been attached below.

Example Program

import java.io.FileWriter;

import java.io.IOException;

import java.io.StringWriter;

import java.util.LinkedHashMap;

import java.util.LinkedList;

import java.util.Map;

import org.json.JSONArray;

import org.json.JSONObject;

public class WriteJsontoFile

{

	public static void main(String[] args)

	{

		JSONArray list1 = new JSONArray();

		list1.put("foo");

		list1.put(new Integer(100));

		list1.put(new Double(1000.21));

		JSONArray list2 = new JSONArray();

		list2.put(new Boolean(true));

		list2.put(null);

		JSONObject obj = new JSONObject();

		obj.put("name", "foo");

		obj.put("num", new Integer(100));

		obj.put("balance", new Double(1000.21));

		obj.put("is_vip", new Boolean(true));

		obj.put("nickname", null);

		obj.put("list1", list1);

		obj.put("list2", list2);

		System.out.println(obj);

	}
}

Output

                        {“balance”:1000.21,”list2″:[true,null],”num”:100,”list1″:

                        [“foo”,100,1000.21],”nickname”:null,”is_vip”:true,”name”:”foo”}

BACK

Filed in: JSON Tutorial

Comments are closed.