Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol JSONParser

Tags:

java

json

android

So I have imported import org.json.* and It doesnt seem to recognize JSONParser.

String filePath = "C://CN//jokes.json";
 try {
        FileReader reader = new FileReader(filePath);
        JSONParser jsonParser = new JSONParser();
        JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
        System.out.println(jsonObject);
    }catch (Exception e) {
        System.out.println(e);
    }
}

jokes.json has the same information as http://api.icndb.com/jokes I want to be able to get the data from that site, but to test I have created a file. This is my first time using Json so I'm a bit clueless. I have updated the jdk and jre, but I still have the same issue. Here is a screenshot showing how it looks: Screenshot I have also read a similar post link, but it is different from my problem.

If you look at the screenshot it seems import org.json.* doesnt have class JSONParser. I have also tried adding import org.json.simple.parser.JSONParser; but it doesnt recognize it. because "simple" doesnt exist

like image 879
Java Gamer Avatar asked Nov 29 '22 06:11

Java Gamer


1 Answers

For Android Studio, just add this to the build.gradle dependencies:

compile 'com.googlecode.json-simple:json-simple:1.1'

For other IDEs and other options, see here: http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1

like image 132
Java Gamer Avatar answered Nov 30 '22 19:11

Java Gamer