I was able to successfully download json in my gradle dependencies:
implementation 'org.json:json:20171018'
Answer from David Miller on Stack OverflowI was able to successfully download json in my gradle dependencies:
implementation 'org.json:json:20171018'
As some mentioned, mvnrepository provides snippet for different Build systems.
After you choose your desired version, in the middle of the page, select Gradle as build system, copy and paste the snippet in your build.gradle file, section dependencies in your java project.
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20180813'
android studio cannot resolve import org.json.JSONObject - Stack Overflow
Unable to add Json Dependency in build.gradle
can't import json to gradle
java - Gradle Jar Dependency Error - Stack Overflow
If you download the JSON jar specified, and list its contents (e.g. with jar tf), it does not contain the org.json.simple package.
So the problem is simply that you need another jar.
EDIT:
I don't know if this is the intent, but an educated guess: if you add this dependency to build.gradle:
compile 'com.googlecode.json-simple:json-simple:1.1.1'
and these imports:
import org.json.simple.parser.*;
// import org.json.simple.*;
import org.json.*;
then the example compiles (for me).
Adding this to my build.gradle file works:
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
I had already installed json-simple-1.1.1.jar
I had already added this below to build.gradle and I use windows 10.
dependencies {implementation "G:\document\org.json:json:20171018" }
I still got the same error message: "The import org.json cannot be resolved".
Hi all,
I am working with a JSON object and when I launch my project I get the following error:
java.lang.NoClassDefFoundError: org/json/JSONObject
viewmodels.LaunchViewModel.buildNextLaunch(LaunchViewModel.java:64)Looking at line 64...
JSONObject jsonObj = new JSONObject(getHTML("..."));Looks like I have not setup the dependencies correctly. I am working with IntelliJ with Gradle and I have imported JSON into my external libraries as seen here...
https://i.imgur.com/8VqLFf9.jpg
and here...
https://i.imgur.com/MFupkXg.jpg
My question is does it need to be added to the build.gradle file? Here are my dependencies:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
}I think that may be the culprit? But I am still pretty new to this process so any pointers would be sweet.
Thanks!
Edit for mods: The two screenshots are of my external libraries, no code in those. I replaced the remaining screen shot with a code block. Thanks!