How to Create JSON in Java ?
we can easily create JSON in java Using org.json.simple library .so build this jar into your application .
public class JSON{
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Name", "Anand");
jsonObject.put("Age", new Integer(23));
jsonObject.put("Married",new Boolean(false));
System.out.println(jsonObject);
/*
{"Married":false,"Age":23,"Name":"Anand"}
*/
}
public class JSON{
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Name", "Anand");
jsonObject.put("Age", new Integer(23));
jsonObject.put("Married",new Boolean(false));
JSONArray jsonarray = new JSONArray();
jsonarray.add(jsonObject);//
System.out.println(jsonarray);
/*
[{"Married":false,"Age":23,"Name":"Anand"}]
*/
}
- Create JSONObject :
public class JSON{
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Name", "Anand");
jsonObject.put("Age", new Integer(23));
jsonObject.put("Married",new Boolean(false));
System.out.println(jsonObject);
/*
{"Married":false,"Age":23,"Name":"Anand"}
*/
}
- Create JSONArray :
public class JSON{
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("Name", "Anand");
jsonObject.put("Age", new Integer(23));
jsonObject.put("Married",new Boolean(false));
JSONArray jsonarray = new JSONArray();
jsonarray.add(jsonObject);//
System.out.println(jsonarray);
/*
[{"Married":false,"Age":23,"Name":"Anand"}]
*/
}
Comments
Post a Comment