-2
好的,我有一個登錄屏幕,它將用戶名和密碼發送到PHP頁面。根據登錄狀態,PHP頁面的回顯爲「是」或「否」,但我希望它從數據庫回顯用戶標識以供進一步使用。我必須爲此使用JSON嗎?我不知道如何檢索多個回聲。目前的代碼是:從PHP中拉出超過1個回顯OK
- (IBAction) login: (id) sender
{
NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",usernameField.text, passwordField.text];
NSString *hostStr = @"https://www.mysite.com/login.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"Yes"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Business Manager" message:@"Login Successful"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
RootViewController *viewMenu = [[RootViewController alloc]
initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
self.rootViewController = viewMenu;
[viewMenu release];
[self.navigationController pushViewController:self.rootViewController animated:YES];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
}
}
現在我只想再拉一個叫做「ID」的回聲。爲此形成JSON似乎是任意的。