转换数组中的字符串

时间:2010-11-03 18:27:10

标签: iphone objective-c

我在这里有一个小问题。我正在使用表单进行登录,将字符串发送到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);

}

谢谢!

1 个答案:

答案 0 :(得分:0)

在大多数情况下,您希望回复位于XMLJSON

如果您有控制权,可以访问API,我建议您尝试使用该路由而不是数组

相关问题