How to parse JSONObject
from the server. I got the response from the server as
{
"status": "success",
"authKey": "$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"
}
How to parse JSONObject
from the server. I got the response from the server as
{
"status": "success",
"authKey": "$2y$13$fg2dFdy7KbSsZP.WIddETOYxOCtJHtFwwGDTJudQ6w7hQcH5vGm16"
}
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();
}
try {
JSONObject jsonObj =new JSONObject("your response string");
String status = jsonObj.optString("status");
String authKey = jsonObj.optString("authKey");
} catch (JSONException e) { e.printStackTrace(); }
try {
JSONObject jsonObject = new JSONObject(response.toString());
String status = jsonObject.optString("status");
String authKey = jsonObject.optString("authKey");
} catch (JSONException e) {
e.printStackTrace();
}
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.
JSONObject jsonObject = new JSONObject(response);
String status= jsonObject.getString("status");
String authKey = jsonObject.getString("authKey");