android studio cannot resolve import org.json.JSONObject(android studio 无法解析导入 org.json.JSONObject)
问题描述
我使用 libgdx 构建我的项目,但在使用 JSONObject 类时遇到问题.当我添加 import org.json.JSONObject
时,它说它无法解析.如何将该库添加到我的项目中?
I used libgdx to build my project and I am having issues using the JSONObject class. When I add import org.json.JSONObject
, it says it cannot resolve. How do I add that library to my project?
这是我尝试过但没有成功的方法:
Here is what I have tried without success:
- 我下载了
json-simple-1.1.jar
并将其放在 core/build/libs 文件夹中.也无法使用import.org.json.simple.JSONObject
. - 在 Android Studio 中以Packages"下拉菜单浏览树时,我可以在
Core -> Libraries -> org -> json"下看到我想要的类
,但我无法添加他们到我的项目.我收到无法折射,类在 jar 文件中"错误.
- I downloaded the
json-simple-1.1.jar
and put it in core/build/libs folder. Could not useimport.org.json.simple.JSONObject
either. - When browsing the tree in Android Studio as "Packages" dropdown, I can see the classes I want under
"Core -> Libraries -> org -> json"
but I cannot add them to my project. I get a "cannot refractor, class is in a jar file" error.
我还没有尝试解决这个问题吗?当我尝试使用其他外部库时,我觉得我会再次遇到这个问题.
Is there something I have not tried yet to solve this issue? I feel I will run into this again as I try to use other external libraries.
谢谢.
推荐答案
如果您使用的是 LibGdx,它不附带 Gradle 设置,可以简化多项目构建.
If you are using LibGdx, it does not come with a Gradle setup, making multi-project builds streamlined.
您需要将 implementation 'org.json:json:<version>'
添加到顶级 build.gradle
的依赖项块中.
You need to add implementation 'org.json:json:<version>'
to the dependencies block of your top-level build.gradle
.
要查找最新版本,请参阅 http://mvnrepository.com/artifact/org.json/json/
To find the latest version, see http://mvnrepository.com/artifact/org.json/json/
例如,使用撰写本文时的最新版本:
For example, using the latest version at the time of writing:
dependencies {
implementation 'org.json:json:20200518'
}
这篇关于android studio 无法解析导入 org.json.JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android studio 无法解析导入 org.json.JSONObject


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01