Kotlin Youtube - How to Quickly Fetch Parse JSON with OkHttp and Gson (Ep 2)

Lets Build That App · 86K views · 2017 · 26:14

Open on YouTube

Software practice, open source & careersWeb developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering or asking how to fetch and parse JSON in Kotlin on Android with OkHttp and Gson.

Recommended by 3 people across 3 different months, 2018 to 2019.

What it is

Episode 2 of a Kotlin Android series by Lets Build That App. It shows how to fetch JSON from a REST endpoint with OkHttp, parse it into model objects with Gson, and render the resulting list of videos in a RecyclerView adapter.

What people said

Recommends Zim · 2018-04 · Stack Overflow · on “Kotlin API call using Retrofit”

After much googling, I finally solved my problem thanks to How to Quickly Fetch Parse JSON with OkHttp and Gson [this video] on YouTube. fun fetchBooks () { println("fetching books") val url = " [LINK] " val request = Request.Builder().url(url).build() println(request) val client = OkHttpClient() client.newCall(request).enqueue(object: Callback { override fun onResponse(call: Call?, response: Response?) { val body = response?.body()?.string() println(body) } override fun onFailure(call: Call?, e: IOException?) { println("Failed to execute request") e?.printStackTrace() } }) } Still need to format the data and figure out how to turn on wifi in my Android emulator but at least I can consume the JSO

Recommends Eldar · 2019-07 · Stack Overflow · on “How to solve: Failed to parse XML configuration from network_security_config”

I'm trying to get json from an api, using okhttp and when i try to do so the app is crushing and i get a runtime Exception Failed to parse XML configuration from network_security_config what should i do to solve it? i have INTERNET permission on my manifest. i'v tried to search for something similar on other questions and could't find an answer. I've tried to follow this tutorial: [this video] but it seems that there is some problem with the XML but i don't understand it. here is my class: class TestActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_test) val adapter = ArrayAdapter<User>(this, a

Recommends kristhian deoliveira · 2019-08 · Stack Overflow · on “JSON Objects from an API combined with Google Maps - Homework”

To display a list of items similar to a ListView I would use an adaptor, here is a good resource from a reputable source. [LINK] To parse JSON here is another resource that should help you understand JSON in Android. [this video]

Cites daydr3am3r · 2018-03 · Stack Overflow · on “Kotlin - Unable to parse JSON”

I am trying to parse a JSON using Kotlin (I'm new to Kotlin / Android) and I can't seem to find a way to get it done. [{ "submission_date": "March 2018", "user_answers": [{ "question_id": 0, "answer": 5 }, { "question_id": 1, "answer": 5 }] }, { "submission_date": "March 2018", "user_answers": [{ "question_id": 0, "answer": 0 }, { "question_id": 1, "answer": 0 }] }] After trying for some time with Klaxon I decided to give GSON a try and start following this: [this video] The code seems pretty straight forward: val gson = GsonBuilder().create() val userSessions = gson.fromJson(userDataJSON, UserSession::class.java) Here are the models: class UserSession(submissionDate : String) { var submissionDat