JSONObject cannot be resolved to a type

我是研究僧i 提交于 2020-06-26 06:14:10

问题


I cannot import JSONObject, I thought this was something that came with java and an external jar is not needed, why is it saying it cannot find it?


回答1:


I thought this was something that came with java and an external jar is not needed

No - JsonObject is only in JavaEE. JSONObject isn't included in JavaSE, it needs an external library. You can find it on github. However, if you use JavaEE, it is included.

If you are using gradle, add the following to your build.gradle file (available in maven central):

dependencies {
    compile "org.json:json:20171018"
}



回答2:


You need to use the following library in Java SE: https://jsonp.java.net/

The JSR 353: Java API for JSON Processing is only in Java EE by default, not in Java SE.



来源:https://stackoverflow.com/questions/26439675/jsonobject-cannot-be-resolved-to-a-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!