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

android studio cannot resolve import org.json.JSONObject(android studio 无法解析导入 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:

  1. 我下载了 json-simple-1.1.jar 并将其放在 core/build/libs 文件夹中.也无法使用 import.org.json.simple.JSONObject.
  2. 在 Android Studio 中以Packages"下拉菜单浏览树时,我可以在 Core -> Libraries -> org -> json"下看到我想要的类,但我无法添加他们到我的项目.我收到无法折射,类在 jar 文件中"错误.
  1. I downloaded the json-simple-1.1.jar and put it in core/build/libs folder. Could not use import.org.json.simple.JSONObject either.
  2. 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

基础教程推荐