-2

I got this response from my server. I need to extract the value of "token" from the JSON file. I want a variable to contain "hello" at the end. How can I do that in Android Studio (Java)?

PS: I have changed the token to "hello" for security sakes

{
"token":"hello",
"refresh_token":"hey"
}
1
  • are you using retrofit for api ? Commented Apr 13, 2019 at 9:19

2 Answers 2

0

You can use JSONObject to get your value from your server response:

  JSONObject jsonObject = new JSONObject(your response);
  jsonObject.get("token"); // this will get you the value for the key "token"
Sign up to request clarification or add additional context in comments.

Comments

0

org.json.JSONObject is the class for obtaining the JSON (Javascript Object Notation) object. As soon as you retrieve the response string by calling the login API, just parse the response onto JSON object and get the key (here "token" in your case) like : JSONObject loginJSONObject = new JSONObject(result); String access_token = loginJSONObject.getString("token");.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.