简体   繁体   中英

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\" : \"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

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 :(

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM