2010-11-03 61 views
0

我在這裏有一個小問題。我正在做一個表單登錄,發送字符串到PHP,回到我最後的答案,「錯誤」或「確定」。轉換數組中的字符串

但是,我需要PHP返回一點點比它,如名稱等,我想顯示這個名字在一個標籤。所以,爲此,我需要一個數組,對嗎?

那麼,我該如何做到這一點?

NSMutableURLRequest *request = 
[[NSMutableURLRequest alloc] initWithURL: 
[NSURL URLWithString:@"http://localhost/dev/mcomm/login.php"]]; 

[request setHTTPMethod:@"POST"]; 
NSString *postString = [[NSString alloc] initWithFormat:@"email=%@&pass=%@", email.text, senha.text]; 

[request setValue:[NSString 
        stringWithFormat:@"%d", [postString length]] 
forHTTPHeaderField:@"Content-length"]; 

[request setHTTPBody:[postString 
         dataUsingEncoding:NSUTF8StringEncoding]]; 

[[NSURLConnection alloc] 
initWithRequest:request delegate:self]; 


//get response 
NSHTTPURLResponse* urlResponse = nil; 
NSError *error = [[NSError alloc] init]; 
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; 
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
NSLog(@"Response Code: %d", [urlResponse statusCode]); 
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) { 
    NSLog(@"Response: %@", result); 

} 

謝謝!

回答

0

在大多數情況下,您會希望響應在XMLJSON

如果您有控制權,可以訪問API我建議您嘗試去那條路線而不是陣列