1
votes

I use this method to access my mysql database from Xcode:

NSString *URL = [NSString stringWithFormat:@"http://test.test:8888/test/loadUserData.php?username=%@", userName];

NSString *rawJSON = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:URL]];

const char *convert = [rawJSON UTF8String]; NSString *responseString = [NSString stringWithUTF8String:convert];

if ([rawJSON length] == 0) { [rawJSON release];

}

SBJsonParser *parser = [[SBJsonParser alloc] init];

userInfo = [[parser objectWithString:responseString error:nil] copy]; SSN = [userInfo objectAtIndex:0];

[parser release];

return userInfo;

Everything works great. EXCEPT that I can't compare strings in the result with normal nsstrings. If I say

if ([userinfo objectAtIndex:0) == @"Dan") { ..do something }

Xcode never sees that it is the same value.. I don't know if there is something wrong with the format (My database is UTF-8) And how can I convert the result so xCode can compare the response with NSStrings?

Thanks!

2
What does this have to do with Xcode?user142019

2 Answers

1
votes

== does not compare the value of strings, it just compares their addresses.

Use

if ([[userinfo objectAtIndex:0] isEqualToString:@"Dan"]) { ... } 

or something similar instead.

1
votes

If you know for sure that you have string data on both sides of the condition you could use

if ([userinfo objectAtIndex:0] isEqualToString:@"Dan") {
    // summat...
}