Tutorialspoint Examples: How To Use JSON Object in Java?
Tutorialspoint Examples: How To Use JSON Object in Java?
Tutorialspoint examples
(http://tutorialspointexamples.com)
Learn java tutorial with examples for beginners online
Search
How To Use JSON Object In Java?
Let us discuss how to use JSON object in java with the help of below example.
Steps:
1. Include JSON jar in classpath.
2. Create JSONObject object.
3. Add data to JSONObject.
3. Process the object.
Example:
JSONTest.java
package com.javawithease.business;
import net.sf.json.JSONObject;
/**
* This class show use JSON object in java.
* @author javawithease
*/
public class JSONTest {
public static void main(String args[]){
//Create JSON object
JSONObject obj = new JSONObject();
//Add data to JSON object.
obj.put("name", "Bharat");
obj.put("rollNo", "MCA/07/05");
obj.put("id", new Integer(50));
//Print JSON object.
System.out.print(obj);
}
}
Output:
http://tutorialspointexamples.com/jsonobjectinjava/ 1/5
1/12/2016 How to use json object in java | Tutorialspoint examples
{"name":"Bharat","rollNo":"MCA/07/05","id":50}
Download this example. (http://tutorialspointexamples.com/wp
content/uploads/2015/06/JSONExample1.rar)
Next Topic: How to parse json in java with example? (http://tutorialspointexamples.com/howto
parsejsoninjavawithexample/)
Previous Topic: How to access json object array in javascript?
(http://tutorialspointexamples.com/howtoaccessjsonobjectarrayinjavascript/)
Related Topics:
How to build java project using ant in eclipse? (http://tutorialspointexamples.com/howtobuildjava
projectusingantineclipse/)
JAXB marshalling – convert java object to xml example. (http://tutorialspointexamples.com/jaxb
marshallingconvertjavaobjecttoxmlexampleusingonepojo/)
How to create pdf file in java using iText jar? (http://tutorialspointexamples.com/howtocreatepdffile
injavausingitextjar/)
Generics class example. (http://tutorialspointexamples.com/genericsclassexample/)
OGNL in struts 2. (http://tutorialspointexamples.com/ognlinstruts2/)
Hibernate OnetoOne Mapping using xml. (http://tutorialspointexamples.com/hibernateonetoone
mappingusingxml/)
Send inline image in email using JavaMail API. (http://tutorialspointexamples.com/sendinlineimage
inemailusingjavamailapi/)
Quartz 2 JobListener example. (http://tutorialspointexamples.com/quartz2joblistenerexample/)
JSON Tutorial
JSON overview. (http://tutorialspointexamples.com/jsonoverview/)
JSON format and data types (http://tutorialspointexamples.com/jsonformatanddatatypes/)
JSON object from string. (http://tutorialspointexamples.com/howtocreatejsonobjectfromstringin
javascript/)
Access json object array. (http://tutorialspointexamples.com/howtoaccessjsonobjectarrayin
javascript/)
JSON object in java. (http://tutorialspointexamples.com/howtousejsonobjectinjava/)
Parse json in java. (http://tutorialspointexamples.com/howtoparsejsoninjavawithexample/)
Download JSON jar. (http://tutorialspointexamples.com/wpcontent/uploads/2015/06/JSONLib.rar)
http://tutorialspointexamples.com/jsonobjectinjava/ 2/5