__NSCFBoolean isEqualToString:]: unrecognized selector sent to the instance

when I get values ​​from PHP JSON , then I get a problem for __NSCFBoolean isEqualToString :

My code is as follows:

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection { //convert to JSON for(id key in res) { id value = [res objectForKey:key]; NSString *keyAsString = (NSString *)key; NSString *valueAsString = (NSString *)value; //NSCFBoolean /*if([value isKindOfClass:[NSNumber class]]) { printf("Number"); } else if([value isKindOfClass:[NSString class]]) { printf("String --- \n"); if([value isEqualToString:@"0"]) { printf("Wrong \n"); } else { printf("Right \n"); } }*/ NSLog(@"%@",[valueAsString class]); if([keyAsString isEqualToString:@"success"]) { printf("Working \n"); } else { printf("Not Working\n"); } //Error is in below line if([valueAsString isEqualToString:@"0"])// strcmp([value objCType], @encode(BOOL)) == 1) { [self loginSuccess]; } else if(strcmp([value objCType], @encode(BOOL)) == 0) { [self loginFailure]; } NSLog(@"key: %@", keyAsString); NSLog(@"value: %@", valueAsString); } 

}}

Getting problem [__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x1dc9964

Google search for this problem since yesterday, but there is no solution yet. NSCFBoolean is also not available in iOS 6.0, currently. So what could I do to check "0" or "1" from a JSON string? Please help.

+6
source share
2 answers

value is an NSNumber object (__NSCFBoolean, because NSNumber is a class cluster), not a string! Use [value boolValue] to determine 0 or 1.

Casting an object does not change its type!

+19
source

Here is the suspicious part:

 if([keyAsString isEqualToString:@"success"] && [valueAsString isEqualToString:@"0"]) { } 

Either keyAsString, valueAsString (possibly this one), or both are not string objects. What for? We cannot know this from your code, perhaps you are doing something wrong with JSON data. Show us more code, please.

EDIT

Try the following:

 if([keyAsString isEqualToString:@"success"] && [valueAsString isEqualToNumber:@(NO)]) { } 
0
source

All Articles