将JSON导入Eclipse项目

时间:2023-01-17 18:10:56

I'm an aspiring Java programmer looking to use JSON in a project. I was following a programming tutorial (from a book) which asked me to import JSON into my project by using the following line:

我是一个有抱负的Java程序员,希望在项目中使用JSON。我正在学习一个编程教程(来自一本书),它要求我使用以下代码将JSON导入到我的项目中:

import com.google.appengine.repackaged.org.json.JSONArray; 

But this produced an error, so I replaced it with this line:

但是这产生了一个错误,所以我用这句话来替换它:

import org.json.JSONArray;

This also produces a (different) error:

这也会产生(不同的)错误:

The import org.json cannot be resolved

import org。json无法解决

I think the problem is that I don't actually have the JSON library in my Eclipse workspace. How can I do this, so I can use the JSONArray? I found the website for JSON, but am not sure what to download or how or where to install it:

我认为问题在于我的Eclipse工作区中实际上没有JSON库。我要怎么做才能使用JSONArray?我找到了JSON的网站,但我不知道该下载什么,或者如何安装它:

http://json.org/java/

http://json.org/java/

6 个解决方案

#1


127  

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.

从这个URL下载ZIP文件并提取它以获取Jar。将Jar添加到构建路径中。要检查此Jar中的可用类,请使用此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

要将这个Jar添加到构建路径右击项目>构建路径>配置构建路径>选择Libraries标签>点击添加外部库>选择Jar文件下载

I hope this will solve your problem

我希望这能解决你的问题。

#2


5  

You should take the json implementation from here : http://code.google.com/p/json-simple/ .

您应该从这里获取json实现:http://code.google.com/p/json-simple/。

  • Download the *.jar
  • 下载* . jar
  • Add it to the classpath (right-click on the project, Properties->Libraries and add new JAR.)
  • 将它添加到类路径(右键单击项目,Properties->库并添加新的JAR)。

#3


1  

It still doesn't work for me, but at least I don't get the JSON library error anymore. Copy json-1.5.jar into the main folder from here link, not into the library one and then replace every import com.google.appengine.repackaged.org.json.JSONArray; with import org.json.JSONArray; like you pointed out. Still I get the following warning every time I try to access the Datastore:

它对我仍然不起作用,但至少我不再得到JSON库错误。复制json - 1.5。jar从这里链接到主文件夹中,而不是在库1中,然后替换每个import com.google. appengine.repackagage . org.json.jsonarray;与进口org.json.JSONArray;像你这样指出。每次尝试访问数据存储时,仍然会收到以下警告:

com.google.appengine.tools.development.LocalResourceFileServlet doGet
WARNING: No file found for: /favicon.ico

Did you manage to make the code work in the end?

最后你成功地让代码工作了吗?

#4


1  

Download json from java2s website then include in your project. In your class add these package java_basic;

从java2s网站下载json,然后包含在你的项目中。在类中添加这些包java_basic;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

#5


-1  

Download the json jar from here. This will solve your problem.

从这里下载json jar。这将解决你的问题。

#6


-3  

Download java-json.jar from here, which contains org.json.JSONArray

下载java-json。jar从这里开始,它包含org.json.JSONArray

http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip

http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip

nzip and add to your project's library: Project > Build Path > Configure build path> Select Library tab > Add External Libraries > Select the java-json.jar file.

nzip并添加到项目库:项目>构建路径>配置构建路径>选择库选项卡>添加外部库>选择java-json。jar文件。

#1


127  

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.

从这个URL下载ZIP文件并提取它以获取Jar。将Jar添加到构建路径中。要检查此Jar中的可用类,请使用此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

要将这个Jar添加到构建路径右击项目>构建路径>配置构建路径>选择Libraries标签>点击添加外部库>选择Jar文件下载

I hope this will solve your problem

我希望这能解决你的问题。

#2


5  

You should take the json implementation from here : http://code.google.com/p/json-simple/ .

您应该从这里获取json实现:http://code.google.com/p/json-simple/。

  • Download the *.jar
  • 下载* . jar
  • Add it to the classpath (right-click on the project, Properties->Libraries and add new JAR.)
  • 将它添加到类路径(右键单击项目,Properties->库并添加新的JAR)。

#3


1  

It still doesn't work for me, but at least I don't get the JSON library error anymore. Copy json-1.5.jar into the main folder from here link, not into the library one and then replace every import com.google.appengine.repackaged.org.json.JSONArray; with import org.json.JSONArray; like you pointed out. Still I get the following warning every time I try to access the Datastore:

它对我仍然不起作用,但至少我不再得到JSON库错误。复制json - 1.5。jar从这里链接到主文件夹中,而不是在库1中,然后替换每个import com.google. appengine.repackagage . org.json.jsonarray;与进口org.json.JSONArray;像你这样指出。每次尝试访问数据存储时,仍然会收到以下警告:

com.google.appengine.tools.development.LocalResourceFileServlet doGet
WARNING: No file found for: /favicon.ico

Did you manage to make the code work in the end?

最后你成功地让代码工作了吗?

#4


1  

Download json from java2s website then include in your project. In your class add these package java_basic;

从java2s网站下载json,然后包含在你的项目中。在类中添加这些包java_basic;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

#5


-1  

Download the json jar from here. This will solve your problem.

从这里下载json jar。这将解决你的问题。

#6


-3  

Download java-json.jar from here, which contains org.json.JSONArray

下载java-json。jar从这里开始,它包含org.json.JSONArray

http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip

http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip

nzip and add to your project's library: Project > Build Path > Configure build path> Select Library tab > Add External Libraries > Select the java-json.jar file.

nzip并添加到项目库:项目>构建路径>配置构建路径>选择库选项卡>添加外部库>选择java-json。jar文件。