Cristian Romero
Cristian Romero

Reputation: 55

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)

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

Answers (1)

georkost
georkost

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

Related Questions