I am parsing a JSON string:
Response: {"success":false,"displaymessage":"UserName or Email already exist. Please try again"}
The code I am using is:
NSLog(@"Result: %@ %@", [responseObject valueForKeyPath:@"success"]? @"YES" : @"NO", [responseObject valueForKeyPath:@"displaymessage"]);
However my out put is:
Result: YES UserName or Email already exist. Please try again
I should be getting a No. What am I doing wrong?
The
valueForKeyPath:method returns an object, which is always non-nil (hence you’re seeing aYESinstead of aNO). If I remember it correctly, booleans are wrapped inNSNumber. You should pull the actual boolean value from the object returned byvalueForKeyPath:, like this: