adrian
adrian

Reputation: 4594

acces JSON from server side

I have the following response from server:

{"_license":false}

And when I try to get out from there _license it displays null.I tried like this:

NSString *items = [[parser objectWithString:[request responseString] error:nil] valueForKey:@"_license"];
NSLog(@"response server%@", items);

Any idea why?And how to solve?

Upvotes: 0

Views: 78

Answers (2)

rckoenes
rckoenes

Reputation: 69499

Try en spilt up your code, don't do every thing in one line. Then check ever variable if it contains the correct value.

NSLog(@"Server response: %@",[request responseString]);
NSError * error = nil;

NSDictionary *response = [parser objectWithString:[request responseString] error:&error]

if (!response)( {
  NSLog( @"Error parsing JSON: %@", error);
  return;
}

NSLog(@"Dictionary: %@", response);

NSNumber *hasValidLicense = [response objectForKey:@"_license"];
NSLog(@"Has valid license: %@", hasValidLicense);

if ([hasValidLicense boolValue]){
   //Yes we have a valid license.
} else {
   // No valid license.
}

Upvotes: 1

Mousa
Mousa

Reputation: 3036

replace your line with the following:

BOOL items = [[[parser objectWithString:[request responseString] error:nil] valueForKey:@"_license"] boolValue];

Upvotes: 0

Related Questions