【发布时间】:2019-06-23 11:07:44
【问题描述】:
我的 JSON 看起来像这样
{"status":true,"error_message":[],"locations":[{"id":"12","name":"office"},{"id":"13","name":"home"}]}
我正在使用协程和改造来与 Web 服务进行通信。我想在locations arrayList 中获得office 和home,但我只能获得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"
}
输出
2
office
2
office
期望的输出
2
offine
2
home
【问题讨论】:
标签: android json kotlin retrofit coroutine