Issue
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. 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. How can I pull data with JSON package?
Solution
You need to learn how to use JSON and Okhttp in Kotlin
First, add dependencies of Okhttp to your project, then create an object from OKHTTPCLIENT()
like this:
val client = OKHTTPCLIENT()
val request = Request.Builder()
.url("URL OF JSON")
.build()
Next, add these following lines of code to onResponse
funtion:
val rawContent = response.body!!.string()
val jsonObject = JSONOBJECT(rawContent)
jsonObject.getInt("ID OF content u want")
Now you have a JSON object there
JSON Docs here : https://developer.android.com/reference/kotlin/org/json/JSONObject
Answered By - HoFa