I am new to iOS. I created a login page and everything works fine. I used JSON for checking username and password and got the response from server in a dictionary format. I want to extract the values from the dictionary and check them in my program. The response which I get from the server is:
json: {
error = 0;
msg = "";
value = {
user = false;
};
};
First I want to check if the value with the key error
is 0
or 1
. Then I want to check the value with the key user
. I don't know how I should code to check it. Can anyone help?
The code which I tried is below:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *respString = [[NSString alloc] initWithData:loginJSONData encoding:NSUTF8StringEncoding];
SBJsonParser *objSBJSONParser = [[SBJsonParser alloc] init];
NSDictionary *json = [[NSDictionary alloc] initWithDictionary:[objSBJsonParser objectWithString:respString]];
NSLog(@"json: %@",json);
NSString *error = [json objectForKey:@"error"];
NSLog(@"error: %@", error);
if ([error isEqualToString:@"o"])
{
NSLog(@"login successful");
}
else
{
NSLog(@"login fail");
}
}