以下是我的PHP代碼發送響應Web服務請求:字符串等於沒有工作的iOS
$query = "select name,email,password from User where email='".$email."' AND password='".$password."'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows==1)
{
sendResponse(200, json_encode("match"));
}
if($num_rows==0)
{
sendResponse(204, json_encode("not match"));
}
以下是我的iOS代碼:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@" Returned Json data : %@",status);
if ([status isEqualToString:@"match"])
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate OpenTabController];
}
//Boolean flag = [status isEqualToString:@"not match"];
//NSLog(@"flag : %d",flag);
if ([status isEqualToString:@"not match"])
{
NSLog(@"not match");
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Invalid email or password"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
線[status isEqualToString:@"not match"]
不起作用。
你有沒有轉換從Web服務的JSON響應中mainuplated成iOS代碼? –
是的,我做到了。 NSString * status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@「返回的Json數據:%@」,狀態); –
並且打印出您期望的消息? – Eric