Q:

Get arraylist in JSON

My JSON looked like this
{"status":true,"error_message":[],"locations":[{"id":"12","name":"office"},{"id":"13","name":"home"}]}

I'm using coroutine and retrofit to communicate with web service. I would like to get office and home in locations arrayList, but I only able to get office.
fun getLocation(): String {
                val service = RetrofitFactory.makeRetrofitService()
                GlobalScope.launch(Dispatchers.Main) {
                    val request = WebApi.getLocationList(context)
                    request?.locations.let {
                        for (i in it!!.iterator()) {
                           longToast(request?.locations!!.size.toString()) 

longToast(request?.locations!!.component1().name.toString())
                        }
                    }
                }           
                return "sss"
            }

Output
2
office
2
office

Desired output
2
offine
2
home

A:

Your toast does not use i from the for loop. Try switching to this:
longToast(i.component1().name.toString())

