In my Android project, when a user logs in, it connects to our server and delivers JSON data to the client. If incorrect username or password is provided, the server responds with JSON data structured as follows:
{
"d": {
"__type": "FMService.LoginUser:#StarHope.FMS.Web.Pages.Service",
"Error": "wrong",
"Permissions": null,
"UserInfo": null
}
}
However, when the user inputs the correct username and password, the value returned from the "Error" key is null. Is this code the correct way to handle this?
try
{
//when Error is not null
String error = (String) map.get("Error");
}
catch (Exception e)
{
//when Error is null
}
parse your json string as use
isNullto check ifjsonobjectcontent NULL or not before adding value to Map: