I was able to successfully download json in my gradle dependencies:
implementation 'org.json:json:20171018'
Answer from David Miller on Stack Overflowjava - Gradle build - not able to import org.json - Stack Overflow
android studio cannot resolve import org.json.JSONObject - Stack Overflow
Import org.json:json as gradle dependency
Unable to add Json Dependency in build.gradle
I 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'
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!
I'm going to start by saying I'm a complete novice in Java. I've started computer science recently and I've got a project where I have to create a project to represent a server using sockets. The server will has to function as a control a library's book record/register. My professor provided a .json file with the book lists which I have to use.
I tried creating the project on VS Code, but after following these steps:
Downloaded the library from the Maven Repository.
Created a lib folder in your project's root directory and move the json-20230303.jar file to this folder.
My code couldn't import the library and this error appeared every time I tried to use the library:
"src\Gerenciador.java:2: error: package org.json does not exist import org.json.JSONArray;"
After a while I thought it would be easier to import the library on the Ide Eclipse, but after creating the project and adding it via the Build Path option, it still didn't work. Even though the library appeared in the Libraries section in the Java Build Path.
This error: "The type org.json.JSONObject is not accessible" keeps appearing.
I don't know how to fix the problem. I think I'm calling on the library wrong, but I don't know how I should do it. If there is any information missing, let me know and I'll provide it, it's my first time asking for help on a programming forum.
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".