You are missing json-simple-1.1.1.jar from your classpath.
if you are using Maven, add below into your pom.xml.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
Or you can download it from here.
Answer from Sundararaj Govindasamy on Stack OverflowVideos
You are missing json-simple-1.1.1.jar from your classpath.
if you are using Maven, add below into your pom.xml.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
Or you can download it from here.
Firstly, you don't need the json-simple.jar in your project.
Therefore remove the import org.json.simple.*
Secondly, the best practice is to import only the required classes from your jar.Therefore you can replace import org.json.*; by
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONString;
Probably your simple json.jar file isn't in your classpath.
I was facing same issue in my Spring Integration project. I added below JSON dependencies in pom.xml file. It works for me.
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
A list of versions can be found here: https://mvnrepository.com/artifact/org.json/json
Download the ZIP file from this URL and extract it to get the Jar. Add the Jar to your build path. To check the available classes in this Jar use this URL.
To Add this Jar to your build path Right click the Project > Build Path > Configure build path> Select Libraries tab > Click Add External Libraries > Select the Jar file Download
I hope this will solve your problem
You should take the json implementation from here : http://code.google.com/p/json-simple/ .
- Download the *.jar
- Add it to the classpath (right-click on the project, Properties->Libraries and add new JAR.)
Bit late, but I wanted to share my opinion on this.
I faced this problem recently when I found a Java project with both libraries and they were used at the same time.
I think that org.json is easier to read and to use, for 2 main reasons (for my needs):
JsonObject is immutable. You can't add new key/value pairs to an already existing JsonObject (reference here: javax.json: Add new JsonNumber to existing JsonObject)
It takes a few lines to pretty print a JsonObject or JsonArray, while it only takes 1 line to do it with JSONObject or JSONArray. Example:
CopyStringWriter sw = new StringWriter(); Map<String, Object> properties = new HashMap<>(); properties.put(JsonGenerator.PRETTY_PRINTING, true); JsonWriterFactory writerFactory = Json.createWriterFactory(properties); JsonWriter jsonWriter = writerFactory.createWriter(sw); jsonWriter.writeObject(jsonObject); //JsonObject created before jsonWriter.close(); String prettyPrintedJSON = sw.toString();
That is the code I use to get an indented JSON to write to a file. And with org.json I only need jsonObject.toString(4).
Another difference is the constructors. You will need a JsonObjectBuilder to create a JSON with javax.json. One step more that can be avoided.
I'm sure there are more differences (not sure if it's possible to create a JsonObject from a String) but these are my thoughts.
JSONObject, as mentioned, is provided by android's API. JsonObject is specifically used for Java EE development which is essentially for web applications and networking capabilities among other things.
The reason Android does not prepackage JsonObject from Oracle Java EE package is because alot of the things javax can do, are not allowed within android like accessing the internet without permission. This means importing the entire jars files of javax would conflict with Android.
If you plan to build your own backend with Java EE, I would highly suggest using JsonObject over JSONObject. On the other hand, if you know a prebuilt rest service or something similar that supports Android's JSON even better.
In my case i was using maven build tool and got this error so had to add below dependency from here like below and error resolved.
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
Class org.json.JSONObject is available in json-20131018.jar. You need to download this jar and add this jar to your buildpath.
In order to add external jar to buildpath you can - right click on your project in eclipse - click build path -> configure build path - goto tab libraries - there you will find to add external JAR
This will allow you to include any external jar into your build path.