How would i get a specific variable in response body after a POST request

compilenoerrors :

I am building an android app that is supposed to edit documents it can get from a remote server. However, to do so i need the user to log in. This should happen like this:

User types in userId and password, POST is sent with this body:

    {
     "username": "normal_username",
     "password": "normal_password"
    }

and when i do so in postman the response body looks like this { "username": "normal_username", "token": "lotsandlotsofnumbersandletters" }

I want to retrieve this token, but i dont know how to do so in android, are there any external libraries that could make this easier for me perhaps?

Code-Apprentice :

Since the response body is JSON, you need to parse it. Use a library such as GSON to do so then you can easily grab the value of the "token" key.

You also might want to look at a library that wraps the entire REST API. Retrofit from Square is one of the most popular libraries that does this.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=307682&siteId=1