Skip to content

Instantly share code, notes, and snippets.

@ibrahim4851
Created May 22, 2021 12:16
Show Gist options
  • Save ibrahim4851/06fdceea3658b42e3893f96878d8f5ed to your computer and use it in GitHub Desktop.
Save ibrahim4851/06fdceea3658b42e3893f96878d8f5ed to your computer and use it in GitHub Desktop.
GetJsonObject
fun getRequest() {
var url = "https://raw.githubusercontent.com/ibrahim4851/VolleyRequests/master/nestedjson.json"
val queue: RequestQueue = Volley.newRequestQueue(this)
val request = JsonObjectRequest(
Request.Method.GET,
url,
null,
{ response ->
val glossary = response.getJSONObject("glossary")
val GlossDiv = glossary.getJSONObject("GlossDiv")
val GlossList = GlossDiv.getJSONObject("GlossList")
val GlossEntry = GlossList.getJSONObject("GlossEntry")
val id = GlossEntry.getString("ID")
val GlossDef = GlossEntry.getJSONObject("GlossDef")
val jsonArray = GlossDef.getJSONArray("GlossSeeAlso")
for (i in 0 until jsonArray.length()) {
var string = jsonArray.getString(i)
Log.i("value", string)
}
},
{ error -> Log.i("errormessage", "Connection Error") })
queue.add(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment