Java JSONObject 无法解析为类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26439675/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:29:57  来源:igfitidea点击:

JSONObject cannot be resolved to a type

javaclassnotfound

提问by code511788465541441

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?

我无法导入 JSONObject,我认为这是 java 附带的东西,不需要外部 jar,为什么说找不到它?

采纳答案by msrd0

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

我认为这是 Java 附带的东西,不需要外部 jar

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

否 -JsonObject仅在 JavaEE 中JSONObject不包含在 JavaSE 中,它需要一个外部库。你可以在github上找到它。但是,如果您使用 JavaEE,则它包含在内。

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

如果您使用的是 gradle,请将以下内容添加到您的build.gradle文件中(在maven central 中可用):

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

回答by EpicPandaForce

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

您需要在 Java SE 中使用以下库:https: //jsonp.java.net/

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

JSR 353: Java API for JSON Processing仅在Java EE中默认情况下,不会在Java SE。