1/12/2016 How to use json object in java | Tutorialspoint examples
Tutorialspoint examples
([Link]
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:
[Link]
package [Link];
import [Link];
/**
* 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.
[Link]("name", "Bharat");
[Link]("rollNo", "MCA/07/05");
[Link]("id", new Integer(50));
//Print JSON object.
[Link](obj);
}
}
Output:
[Link] 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. ([Link]
content/uploads/2015/06/[Link])
Next Topic: How to parse json in java with example? ([Link]
parsejsoninjavawithexample/)
Previous Topic: How to access json object array in javascript?
([Link]
Related Topics:
How to build java project using ant in eclipse? ([Link]
projectusingantineclipse/)
JAXB marshalling – convert java object to xml example. ([Link]
marshallingconvertjavaobjecttoxmlexampleusingonepojo/)
How to create pdf file in java using iText jar? ([Link]
injavausingitextjar/)
Generics class example. ([Link]
OGNL in struts 2. ([Link]
Hibernate OnetoOne Mapping using xml. ([Link]
mappingusingxml/)
Send inline image in email using JavaMail API. ([Link]
inemailusingjavamailapi/)
Quartz 2 JobListener example. ([Link]
94 0 Share 1 Share 0 0 Share 0
0 0 Share 0 92
JSON Tutorial
JSON overview. ([Link]
JSON format and data types ([Link]
JSON object from string. ([Link]
javascript/)
Access json object array. ([Link]
javascript/)
JSON object in java. ([Link]
Parse json in java. ([Link]
Download JSON jar. ([Link]
[Link] 2/5