简体   繁体   English

我有一个 JSON package,我需要在我的应用程序中显示其中的数据,我该怎么做?

[英]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.

相关问题 如何将我的 API JSON 数据显示到回收站视图中 - How do I display my API JSON data into a recycler view 如果我从 3 个不同的 rest API 获取数据,我的存储库中需要有多少 LiveData? - how many LiveData do I need to have in my repositoy if I get data from 3 different rest API? 我需要在我的 android 应用程序中正确显示 json 数据的助手 - I need assistabce displaying json data correctly in my android application 如何显示来自Json的数据 - How can I display data from Json 我的问题是,如何将片段中从JSON获得的列表数据传递给活动? - My questions is, how do I pass the list data i have obtained from JSON in a fragment to an activity? 如果我没有网站,如何命名我的android包 - how to name my android package if I do not have a site 我的Android应用程序中是否需要服务? - Do I need a Service in my android application? 我需要为我的应用程序定位设备吗? - Do I need to target devices for my application? 如何创建应用程序的package文件夹到目录../Android/Data? - How can i create my application's package folder to directory ../Android/Data? 如何仅针对我的库模块/包获取特定于包的崩溃报告/数据(在某些应用程序中通过gradle依赖关系实现) - How do I obtain package specific crash report/data only for my library module/package (implemented in some Application via gradle dependency)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM