将 JSON 导入到 Eclipse 项目中

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

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

但是这样会产生一个错误,所以我用这行代替它:

import org.json.JSONArray;

这还会产生一个(不同的)错误:

无法解析 import org.json

我认为问题在于我的 Eclipse 工作区中实际上没有 JSON 库。我如何做到这一点,以便我可以使用 JSONArray?我找到了 JSON 的网站,但不确定下载什么,如何或在哪里安装:

Http://json.org/java/

398199 次浏览

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

  • Download the *.jar
  • Add it to the classpath (right-click on the project, Properties->Libraries and add new JAR.)

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.

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

I hope this will solve your problem

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

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.

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

Download json from java2s website then include in your project. In your class add these package 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;

on linux pip install library_that_you_need Also on Help/Eclipse MarketPlace, i add PyDev IDE for Eclipse 7, so when i start a new project i create file/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

Add jar to Java build Path

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)