【发布时间】:2011-07-09 02:43:55
【问题描述】:
我需要将通过 PHP 脚本中的数组从 Web 接收到的数据转换为可以从中提取值的数组。这是我的代码!
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
//NSString *payloadAsString = [NSString stringWithUTF8String:[receivedData bytes]];
NSArray *payloadAsString = [NSKeyedUnarchiver unarchiveObjectWithData:receivedData];
[payloadAsString finishEncoding];
verified = [payloadAsString objectAtIndex:0];
NSLog(@"logging");
//NSString *no = [[NSString alloc] init stringWithCString:verified];
NSLog(@"%@", verified);
if([verified isEqualToString:@"admin"]){
NSLog(@"test admin");
[self performSelector:@selector(changeViewAdmin) withObject:nil afterDelay:0.05];
}
if([verified isEqualToString:@"user"]){
NSLog(@"test user");
[self performSelector:@selector(changeView) withObject:nil afterDelay:0.05];
}
if([verified isEqualToString:@"No"]){
NSLog(@"test no");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Invalid UserName/Password combination!"
delegate:self
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}
[payloadAsString release];
//NSLog(@"%@", verified);
// INSERT GOOGLE MAPS URL REQUEST HERE
/*if(requestType == 1){
NSString* addressText = payloadAsString;
// URL encode the spaces
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
// lets throw this text on the log so we can view the url in the event we have an issue
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
// */
//
//}
[connection release];
self.receivedData = nil;
}
不幸的是,我的控制台返回 null 并询问我是否已将 -finishencoding 方法放入。问题是,如果正确,我会在哪里这样做?
PS:另一个问题是,如果我从数据库中检索数据数组,PHP 脚本是最好的方法吗?谢谢。
【问题讨论】:
标签: iphone arrays authentication nsdata nsurl