I’m parsing json for a user authentication system.
If login is successful the server sends following user object;
{
"users": {
"id": "1",
"FB_first_name": null,
"FB_last_name": null,
"FB_gender": null,
"FB_id": null,
"FB_link": null,
"FB_locale": null,
"FB_name": null,
"FB_username": null,
"created_at": "2011-01-02 08:30:59 UTC",
"updated_at": "2011-01-02 08:31:23 UTC",
"email": "admin@8repz.com",
"language_id": "1"
}
}
which I parse using the following code;
NSDictionary *userDic = (NSDictionary*)[(NSDictionary*)results objectForKey:@"users"];
User *aUser = [[User alloc] initWithID:[userDic objectForKey:@"id"]
withUserName:[userDic objectForKey:@"FB_name"]
withUserEmail:[userDic objectForKey:@"email"]
withUserFName:[userDic objectForKey:@"FB_first_name"]];
But in case of invalid user, the server sends following response;
[
"Invalid Email or Password."
]
What if() statement should I use to parse and display the response in both conditions?
1 Answer