Asher Walther
Asher Walther

Reputation: 1327

Importing JSON into an Eclipse project

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:

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

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:

http://json.org/java/

Upvotes: 87

Views: 443388

Answers (7)

Ori Marko
Ori Marko

Reputation: 58892

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)

Upvotes: 7

mariomorle
mariomorle

Reputation: 1

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

Upvotes: 0

Gajender Singh
Gajender Singh

Reputation: 1313

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;

Upvotes: 2

Meowstar
Meowstar

Reputation: 85

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

Upvotes: 0

ESHAN CHATTARAJ
ESHAN CHATTARAJ

Reputation: 21

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.

Upvotes: 0

Ramkumar Murugadoss
Ramkumar Murugadoss

Reputation: 2084

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

Upvotes: 181

Jeremy D
Jeremy D

Reputation: 4855

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

Upvotes: 8

Related Questions