简体   繁体   English

将JSON导入Eclipse项目

[英]Importing JSON into an Eclipse project

I'm an aspiring Java programmer looking to use JSON in a project. 我是一个有抱负的Java程序员,希望在项目中使用JSON。 I was following a programming tutorial (from a book) which asked me to import JSON into my project by using the following line: 我正在按照一本编程教程(从一本书中)请求我使用以下行将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 导入org.json无法解析

I think the problem is that I don't actually have the JSON library in my Eclipse workspace. 我认为问题是我的Eclipse工作区中实际上没有JSON库。 How can I do this, so I can use the JSONArray? 我怎么能这样做,所以我可以使用JSONArray? I found the website for JSON, but am not sure what to download or how or where to install it: 我找到了JSON的网站,但不确定要下载什么或安装方式或位置:

http://json.org/java/ http://json.org/java/

Download the ZIP file from this URL and extract it to get the Jar. 从此URL下载ZIP文件并将其解压缩以获取Jar。 Add the Jar to your build path. 将Jar添加到构建路径中。 To check the available classes in this Jar use this URL . 要检查此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添加到构建路径右键单击项目>构建路径>配置构建路径>选择库选项卡>单击添加外部库>选择Jar文件下载

I hope this will solve your problem 我希望这能解决你的问题

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-> Libraries并添加新的JAR。)

Download json from java2s website then include in your project. 从java2s网站下载json然后包含在你的项目中。 In your class add these package java_basic; 在你的类中添加这些包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;

It still doesn't work for me, but at least I don't get the JSON library error anymore. 它仍然不适合我,但至少我不再得到JSON库错误。 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; 将json-1.5.jar从此处链接复制到主文件夹,而不是复制到库中,然后替换每个导入com.google.appengine.repackaged.org.json.JSONArray; with import org.json.JSONArray; 使用import org.json.JSONArray; like you pointed out. 像你指出的那样。 Still I get the following warning every time I try to access the Datastore: 每次我尝试访问数据存储区时,仍会收到以下警告:

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? 您是否设法使代码最终运行?

在linux pip上安装library_that_you_need同样在Help / Eclipse MarketPlace上,我为Eclipse 7添加PyDev IDE,所以当我启动一个新项目时,我创建了文件/ New Project / Pydev Project

The link of accepted answer is old and can cause warnings with generics use, 接受答案的链接是旧的,可​​能会导致使用泛型的警告

You should download latest jar from JSON-java github site 你应该从JSON-java github网站下载最新的jar

Add jar to Java build Path 将jar添加到Java构建路径

In existing project in Order and Export tab move the new jar, as json-20180813.jar , as the first (or above other dependencies with JSONObject ) Order and Export选项卡中的现有项目中Order and Export将新jar作为json-20180813.jar ,作为第一个(或以上与JSONObject其他依赖项)

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并添加到项目库:Project> Build Path> Configure build path> Select Library选项卡> Add External Libraries>选择java-json.jar文件。

Download the json jar from here . 这里下载json jar。 This will solve your problem. 这将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM