Transforming a String in a Array
I'm having a little question here. I'm doing a login with a form, sending strings to a php, to return to me the final answer, "Error" or "OK".
But, i need to php returns a little bit more than it, like a name and etc, and i want to display this name in a label. So, for this, i'll need a array, correct?
So, how can i do this?
NS开发者_StackOverflowMutableURLRequest *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);
}
Thanks!
it most situations, you would expect the response to be in XML or JSON.
If you have control, access to the API I would suggest you try and go that route instead of an Array
精彩评论