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
Answer from Ramkumar Murugadoss on Stack OverflowDownload 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.)
Videos
so at the top of my serverApplication.java file I have the json import as import org.json.simple.JSONObject;
but it is giving it a red squiggily line...
I also added it as a dependency in y pom.xml as
<dependency>
`<groupId>org.json.simple.JSONObject</groupId>` `<artifactId>JSON package</artifactId>` `<scope>json</scope>` `</dependency>`
it is saying import cannot be resolved
what am I doing wrong?
The whole file is an array and there are objects and other arrays (e.g. cars) in the whole array of the file.
As you say, the outermost layer of your JSON blob is an array. Therefore, your parser will return a JSONArray. You can then get JSONObjects from the array ...
JSONArray a = (JSONArray) parser.parse(new FileReader("c:\\exer4-courses.json"));
for (Object o : a)
{
JSONObject person = (JSONObject) o;
String name = (String) person.get("name");
System.out.println(name);
String city = (String) person.get("city");
System.out.println(city);
String job = (String) person.get("job");
System.out.println(job);
JSONArray cars = (JSONArray) person.get("cars");
for (Object c : cars)
{
System.out.println(c+"");
}
}
For reference, see "Example 1" on the json-simple decoding example page.
You can use jackson library and simply use these 3 lines to convert your json file to Java Object.
ObjectMapper mapper = new ObjectMapper();
InputStream is = Test.class.getResourceAsStream("/test.json");
testObj = mapper.readValue(is, Test.class);
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;