Reputation: 55
it was to ask how I can access different JSON objects in kotlin (they are inside the response)
I'm a newbie, it was to ask what is the best way to handle response objects
Fuel.post("usuario/login").jsonBody("{ \"email\" : \"[email protected]\" , \"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
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 :(
Upvotes: 0
Views: 1373
Reputation: 618
You need to extract the token
json object in order to access it's value.
Something like the following will work
println(JSONObject(response.body).get("token"))
Upvotes: 1