Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios compare boolean from json

Tags:

ios

I got a boolean value from a json object using dictionary. at console, I can see 0 or 1. But my comparision always return true.

BOOL *result =[dictionary valueForKey:@"result"];

        if (result == YES) {

            [parser release];
        }
        else {
            errorLbl.text = @"Login failed";
        }
like image 593
user2514963 Avatar asked Feb 06 '26 13:02

user2514963


2 Answers

have you tried adding a boolValue at the end of [dictionary valueForKey:@"result"]boolValue];

like image 173
CBredlow Avatar answered Feb 08 '26 02:02

CBredlow


You need to convert the value from the dictionary. You can't translate it directly to a BOOL * (BOOL pointer).

Suppose you get a NSString* from your dictionary, you can do:

NSString *result = [dictionary valueForKey:@"result"];
if ([result boolValue]) {
    [parser release];
} else {
    errorLbl.text = @"Login failed";
}

Assuming you can use boolValue message with your protocol.

like image 35
Pablo Santa Cruz Avatar answered Feb 08 '26 04:02

Pablo Santa Cruz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!