2011-10-06 101 views
0

在我的應用程序使用下面的代碼從我的服務器中檢索數據:如何從php頁面讀取數組?

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
NSLog(@"Want to redeem: %@", textField.text); 

NSURL *url = [NSURL URLWithString:@"http://localhost:8888/iPhone/page.php"]; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
[request setDelegate:self]; 
[request startAsynchronous]; 

// Hide keyword 
[textField resignFirstResponder]; 

// Clear text field 
textView.text = @""; 

// Start hud 

return TRUE; 
} 

現在我應該怎麼做才能讓我的$array內容在requestFinished功能

回答

0

我必須爲第一請將您指向ASIHTTPRequest文檔:http://allseeing-i.com/ASIHTTPRequest/How-to-use。但是,你想要做什麼,我覺得是非常簡單的,就像這樣:

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSString *responseString = [request responseString]; 
} 

我希望對您有所幫助,否則我會建議你改一下你的問題。

0

我認爲你需要將PHP輸出格式化爲可以解析成數組的格式...... JSON或XML,然後使用像SBJSON或NSXMLParser(我建議前者)。也許結果是商品信息(爲例),所以你的php將輸出:

[{"id":123,"price":5.99,"itemName":"toy car"},{"id":456","price":0.99,"itemName":"hot coffee"}]

那麼,你會

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
NSArray *responseArray = [[request responseString] JSONValue]; 
//do something with the array 
}