添加JSON包引用;新的Java

时间:2023-01-18 23:26:00

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.

我对Java是全新的,我一直是c类的人。也就是说,我正在尝试使用JSON库(包?课吗?Java术语是如此的令人困惑!)并且我有问题添加它们作为参考。

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?

我访问了json.org并下载了Java库,但我不确定如何使用它们。我试图进入项目属性并添加一个外部类,但没有成功。我注意到下载的文件夹满是.java文件。我该怎么处理这些呢?

Sorry to present such a noob question on here, but I'm stumped.

很抱歉在这里提出这样一个不明确的问题,但我还是被难住了。

4 个解决方案

#1


9  

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.

我相信这是错误的下载。您需要从这里获得JSON-Simple库http://code.google.com/p/json-simple/。您的链接指向另一个实现。

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.

下载后*。jar应该添加到类路径中。如何做到这一点取决于你使用的工具。在Eclipse中,它右键单击项目、Properties->库并添加新的JAR。

#2


15  

  • Right click on the Eclipse project,
  • 右键单击Eclipse项目,
  • choose Properties
  • 选择属性
  • Select Java Build Path
  • 选择Java构建路径
  • Click the libraries tab
  • 单击库选项卡
  • click add external jars
  • 点击添加外部jar
  • find the json jar(s) and add them.
  • 找到json jar并添加它们。

#3


2  

Hey just download the json.jar from this website

嘿,下载json。jar从这个网站

http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm

http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm

after that

在那之后

  • right click on your eclipse project then
  • 然后右键单击eclipse项目
  • choose Properties of that folder
  • 选择该文件夹的属性
  • Select Java Build Path Click the libraries tab
  • 选择Java构建路径单击libraries选项卡
  • click add external jars
  • 点击添加外部jar

find the json jar(s) and add them.

找到json jar并添加它们。

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

并将这些包添加到java文件中:)

#4


0  

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:

注意:Json和JsonSimple是不一样的。如果您正在使用Maven,您可以通过在pom文件中添加这个依赖项来获得json-simple:

http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1

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>

#1


9  

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.

我相信这是错误的下载。您需要从这里获得JSON-Simple库http://code.google.com/p/json-simple/。您的链接指向另一个实现。

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.

下载后*。jar应该添加到类路径中。如何做到这一点取决于你使用的工具。在Eclipse中,它右键单击项目、Properties->库并添加新的JAR。

#2


15  

  • Right click on the Eclipse project,
  • 右键单击Eclipse项目,
  • choose Properties
  • 选择属性
  • Select Java Build Path
  • 选择Java构建路径
  • Click the libraries tab
  • 单击库选项卡
  • click add external jars
  • 点击添加外部jar
  • find the json jar(s) and add them.
  • 找到json jar并添加它们。

#3


2  

Hey just download the json.jar from this website

嘿,下载json。jar从这个网站

http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm

http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm

after that

在那之后

  • right click on your eclipse project then
  • 然后右键单击eclipse项目
  • choose Properties of that folder
  • 选择该文件夹的属性
  • Select Java Build Path Click the libraries tab
  • 选择Java构建路径单击libraries选项卡
  • click add external jars
  • 点击添加外部jar

find the json jar(s) and add them.

找到json jar并添加它们。

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

并将这些包添加到java文件中:)

#4


0  

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:

注意:Json和JsonSimple是不一样的。如果您正在使用Maven,您可以通过在pom文件中添加这个依赖项来获得json-simple:

http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1

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>