我需要比较来自 url 的字符串NSutf8stringencoding
,以便返回 1 或 0,但即使字符串的值为 1,它也总是返回 0。
NSString *strURL = [NSString stringWithFormat:@"http://localhost/signup/login.php?username=%@&password=%@",username.text,password.text];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL
encoding:NSUTF8StringEncoding];
// print the data in strResult
NSLog(@"%@",strResult);
if ([strResult isEqualToString:@"1"])
{
// I need to get the control for main navigation controller
login2ViewController *controller = [[login2ViewController alloc] initWithNibName:@"login2ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES ];
}else
{
// invalid information
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Invalid Information" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
但它总是显示无效的信息,即使里面的内容strResult
是1
。我打印了那个值NSlog
。输出NSLog
:
2012-12-11 16:06:08.156 friend finder[277:11603]
1
如何将该字符串与 进行比较@"1"
?