1

How to parse JSONObject from the server. I got the response from the server as

{
    "status": "success",
    "authKey": "$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"
}
Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42

5 Answers5

1

A JSON object contains key/value pairs like map. The keys are strings and the values are the JSON types. Keys and values are separated by comma.

You can try with this way

             String getStatus = "",authKey="";
            try {
                JSONObject reader = new JSONObject("{"status":"success","authKey":"$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"}"); //Put your Json String  
                getStatus = reader.getString("status");
                authKey = reader.getString("authKey");
                } 
               catch (JSONException e) {
                e.printStackTrace();
            }
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1
 try {
    JSONObject jsonObj =new JSONObject("your response string");
    String status = jsonObj.optString("status");
    String authKey = jsonObj.optString("authKey");
} catch (JSONException e) {   e.printStackTrace(); }
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Manikanta Ottiprolu
  • 751
  • 1
  • 7
  • 23
0
try {
    JSONObject jsonObject = new JSONObject(response.toString());

    String status = jsonObject.optString("status");
    String authKey = jsonObject.optString("authKey");
} catch (JSONException e) {
    e.printStackTrace();
}
Linh
  • 57,942
  • 23
  • 262
  • 279
faiyaz meghreji
  • 271
  • 1
  • 2
  • 9
-1

Here is solution

try{
  JSONObject object = new JSONObject(response)
  String status = oject.getString("status")
  String authKey = oject.getString("authKey")
}catch(Exception e){ e.printStackTrace();}

Hope it will help you.

Sanwal Singh
  • 1,765
  • 3
  • 17
  • 35
-1
JSONObject jsonObject = new JSONObject(response);
String status= jsonObject.getString("status");
String authKey = jsonObject.getString("authKey");
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198