[英]How to use response object in kotlin
it was to ask how I can access different JSON objects in kotlin (they are inside the response)这是问我如何在 kotlin 中访问不同的 JSON 对象(它们在响应中)
I'm a newbie, it was to ask what is the best way to handle response objects我是新手,问的是什么是处理响应对象的最佳方式
Fuel.post("usuario/login").jsonBody("{ \"email\" : \"cristian@admin.com\" , \"password\" : \"123456\"}")
.response { request, response, result ->
//println(response); // body:{token:34urfd9sf9dudu9sj}
println(response.body.token) //error "token" doesn't exist
}
This code is kotlin in android studio此代码是 android studio 中的 kotlin
in response I get several things, one of them is the "token" I thought that to access I only wrote response.token But it doesn't work :(作为回应,我得到了几件事,其中之一是我认为要访问的“令牌”,我只写了 response.token 但它不起作用:(
You need to extract the token
json object in order to access it's value.您需要提取
token
json 对象才能访问它的值。
Something like the following will work像下面这样的东西会起作用
println(JSONObject(response.body).get("token"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.