In the previous section of JSON tutorials you have seen how JSON can be used with JavaScript to create objects and arrays, you have also studied how to parse and create messages with JSON in JavaScript. Now in this part you will study how to use JSON in Java.
To have functionality of JSON in java you must have JSON-lib. JSON-lib also requires following "JAR" files:
JSON-lib is a java library for that transforms beans, collections, maps, java arrays and XML to JSON and then for retransforming them back to beans, collections, maps and others.
In this example we are going to use JSONObject
class for creating an object of JSONObject and then we will print these
object value. For using JSONObject class we have to import following
package "net.sf.json". To add elements in this object we have
used put() method. Here is the full example code of
FirstJSONJava.java is
as follows:
FirstJSONJava.java
import net.sf.json.JSONObject;
|
To run this example you have to follow these few steps
as follows:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JSONObject example in Java View All Comments
Post your Comment