Java 无法解析符号 JSONParser
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36107111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot resolve symbol JSONParser
提问by Java Gamer
So I have imported import org.json.*
and It doesnt seem to recognize JSONParser.
所以我导入了import org.json.*
它似乎无法识别 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/jokesI 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: ScreenshotI have also read a similar post link, but it is different from my problem.
jokes.json 具有与http://api.icndb.com/jokes相同的信息我希望能够从该站点获取数据,但为了进行测试,我创建了一个文件。这是我第一次使用 Json,所以我有点无能为力。我已经更新了 jdk 和 jre,但我仍然有同样的问题。这是显示其外观的屏幕截图: 屏幕截图我也阅读了类似的帖子链接,但它与我的问题不同。
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
如果您查看屏幕截图,它似乎import org.json.*
没有类 JSONParser。我也尝试添加,import org.json.simple.parser.JSONParser;
但它无法识别。因为“简单”不存在
回答by Java Gamer
For Android Studio, just add this to the build.gradle dependencies:
对于 Android Studio,只需将其添加到 build.gradle 依赖项中:
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
有关其他 IDE 和其他选项,请参见此处:http: //mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1
回答by Kaan
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 )
另一个答案有点过时了。(在 2018 年底编译将是 api 或实现,还有一个新版本 1.1.1)
Add this to the build.gradle dependencies:
将此添加到 build.gradle 依赖项:
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 :)
希望它对我有帮助:)
回答by D. Danc
I had the same error and hope this might help somebody.
我有同样的错误,希望这可以帮助某人。
Add this to the build.gradle dependencies:
将此添加到 build.gradle 依赖项:
implementation 'com.google.code.gson:gson:2.8.0'