我需要通過PHP腳本中的數組將數據從網絡接收到的數據轉換爲數組,以便將值從中提取出來。這是我的代碼!將NSData轉換爲數組的NSURLRequest
-(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腳本是最好的方法嗎?謝謝。
你的答案是沒有幫助的,也沒有解決我的問題。我正在尋找能夠解釋如何將在PHP腳本中調用的數組轉換爲可在iPhone程序中使用的數組的人。相反,你所做的只是試圖侮辱我的程序員的能力。我將不勝感激,如果你會編輯你的迴應,使其有幫助。謝謝。 – user298261 2011-03-04 21:30:08
我不是故意侮辱任何人。儘可能地用我卑微的技巧在第1點中講述你的問題,如果不夠,請對不起。我的建議,如果你真的想得到幫助 - 更新您的文章與PHP代碼片段,生成輸出在你的應用程序_或_我用字符串談到的迴應。祝你好運。 – hoha 2011-03-04 22:09:20
剛剛瞭解到PHP數組與iPhone數組的數據類型不同,因此無論如何轉換都是不可能的。 :/感謝您的時間。 – user298261 2011-03-04 22:16:41