12:04 am - Tuesday May 22, 2018

Example program in JSONobject using Map

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 is a sample program which explains about  JSONObject using map and to addition  output of the program has been given 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) {

		Map obj = new LinkedHashMap();

		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);

		String jsonText = JSONValue.toJSONString(obj);

		System.out.print(jsonText);

	}
}


Output

        {“name”:”foo”,”num”:100,”balance”:1000.21,”is_vip”:true,”nickname”:null}

BACK

Filed in: JSON Tutorial, Z-A All Java Codes

Comments are closed.