[英]I have a JSON package and I need to display the data in it in my application, how can I do that?
I am making an application about solar panels and I need to pull the status and efficiency of solar panels from the database with the help of API.我正在制作一个关于太阳能电池板的应用程序,我需要在 API 的帮助下从数据库中提取太阳能电池板的状态和效率。 I found a site, but I couldn't find the API file in it, it only offers JSON packages specific to the region I selected.
我找到了一个站点,但在其中找不到 API 文件,它仅提供特定于我选择的区域的 JSON 包。 How can I pull data with JSON package?
如何使用 JSON package 提取数据?
u need to learn how to use JSON and Okhttp in kotlin你需要学习如何在 kotlin 中使用 JSON 和 Okhttp
first add dependencies of okhttp to ur project首先将okhttp的依赖添加到你的项目中
then create a object from OKHTTPCLIENT() like this:然后从 OKHTTPCLIENT() 创建一个 object,如下所示:
val client = OKHTTPCLIENT()
val request = Request.Builder()
.url("URL OF JSON")
.build()
next add this following codes at onResponse fun
val rawContent = response.body!!.string()
val jsonObject = JSONOBJECT(rawContent)
jsonObject.getInt("ID OF content u want")
now u have a jsonObject here现在你在这里有一个 jsonObject
JSON Doc here: https://developer.android.com/reference/kotlin/org/json/JSONObject JSON 文档在这里: https://developer.android.com/reference/kotlin/org/json/JSONObject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.