Add JSON Package Reference; new to Java

我们两清 提交于 2019-11-29 12:05:06

问题


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.


回答1:


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.




回答2:


  • 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.



回答3:


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 :)




回答4:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!