JSONObject cannot be resolved to a type

code511788465541441 picture code511788465541441 · Oct 18, 2014 · Viewed 31.1k times · Source

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?

Answer

msrd0 picture msrd0 · Oct 18, 2014

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"
}