Cannot resolve symbol JSONParser

Viewed 33708

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

3 Answers

The other answer is a bit out-dated. ( At the end of 2018 compile will be either api or implementation also there is a new version 1.1.1 )

Add this to the build.gradle dependencies:

implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'

and then import

import org.json.simple.parser.JSONParser;

Hope it helps as it does to me :)

I had the same error and hope this might help somebody.

Add this to the build.gradle dependencies:

implementation 'com.google.code.gson:gson:2.8.0'
Related