android studio无法解析导入org.json.JSONObject

Mar*_*koh 13 android json gradle libraries libgdx

我使用libgdx来构建我的项目,我在使用JSONObject类时遇到了问题.当我添加时import org.json.JSONObject,它表示它无法解决.如何将该库添加到我的项目中?

这是我没有成功的尝试:

  1. 我下载json-simple-1.1.jar并将其放在core/build/libs文件夹中.也无法使用import.org.json.simple.JSONObject.
  2. 当在Android Studio中浏览树作为"包"下拉列表时,我可以看到我想要的类,"Core -> Libraries -> org -> json"但我无法将它们添加到我的项目中.我得到一个"不能折射,类是在jar文件中"的错误.

有没有我还没有尝试解决这个问题?当我尝试使用其他外部库时,我觉得我会再遇到这种情况.

谢谢.

Jar*_*ows 28

如果您使用的是LibGdx,它不会带有Gradle设置,从而简化了多项目构建.

请看这里:http://mvnrepository.com/artifact/org.json/json/.

您需要添加compile 'org.json:json:20160212'到您的顶部build.gradle,例如:

dependencies {
   compile 'org.json:json:20160212'
}
Run Code Online (Sandbox Code Playgroud)

  • 请注意,这可能不是预期的实现,因为此库可能仅用于良好 - 请参阅https://wiki.debian.org/qa.debian.org/jsonevil (2认同)