I'm brand new to Java and have always been a c kind-of-guy. That being said, I'm trying to use the JSON libraries (packages? classes? Java terminology is so damn confusing!) and am having issues adding them as a reference.
These three imports cannot be resolved:
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
I went to json.org and downloaded the Java libraries but I'm not sure what to do with them. I've tried to go into project properties and add an external class to no avail. I noticed the downloaded folder is full of .java files. What am I supposed to do with these?
Sorry to present such a noob question on here, but I'm stumped.
This is a wrong download I believe. You need JSON-Simple library from here http://code.google.com/p/json-simple/ . Your link points to another implementation.
After download the *.jar should be added to the classpath. How you do it depends on the tools you use. In Eclipse it is right-click on the project, Properties->Libraries and add the new JAR.
- Right click on the Eclipse project,
- choose Properties
- Select Java Build Path
- Click the libraries tab
- click add external jars
- find the json jar(s) and add them.
Hey just download the json.jar from this website
http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm
after that
- right click on your eclipse project then
- choose Properties of that folder
- Select Java Build Path Click the libraries tab
- click add external jars
find the json jar(s) and add them.
import java.io.FileReader;
import java.util.Iterator;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
and add these package in your java file :)
Be advised: Json and JsonSimple are not the same. If you are using Maven you can get json-simple by adding this dependency to your pom file:
http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
来源:https://stackoverflow.com/questions/5698900/add-json-package-reference-new-to-java