我需要使用比较 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
is 1
。
我打印了这个值NSlog
。输出来自NSLog
:
2012-12-11 16:06:08.156 friend finder[277:11603]
1
我如何将该字符串与@"1"
?
请尝试以下操作 - strResult 中可能存在其他空白字符(如回车符):
if ([strResult rangeOfString:@"1"].length > 0) {
// Do something...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)