我正在我的应用程序中开发注册表单,这里总数据已成功插入到数据库
我得到状态也200响应。但这里我需要从控制台获取数据,这里我正在开发下面的代码。
NSString *myRequestString = [[NSString alloc] initWithFormat:@"customer_name=%@&customer_email=%@&customer_mobile=%@&customer_password=%@&customer_address=%@",name.text,email.text,mobile.text,password.text,add.text];
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:@"http://customer_registration.php"]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
NSURLResponse *response;
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSLog(@"responseData: %@", content);
在这里我得到回复
responseData:
[
{
"customer_id": "14",
"success": "Successfully Registered"
}
]
但是我需要成功
键然后我会打电话
if (success==Successfully Registered) {
LoginViewController *tc=[LoginViewController new];
[self.navigationController pushViewController:tc animated:YES];
}
我尝试了很多方法,但我很困惑什么时候能得到,你能建议我吗,谢谢@
最佳答案
NSString *myRequestString = [[NSString alloc] initWithFormat:@"customer_name=%@&customer_email=%@&customer_mobile=%@&customer_password=%@&customer_address=%@",name.text,email.text,mobile.text,password.text,add.text];
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:@"http://customer_registration.php"]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
NSURLResponse *response;
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSError* error;
NSArray* result = [NSJSONSerialization JSONObjectWithData:returnData
options:kNilOptions
error:&error];
NSLog(@"result: %@", result);
if ([[[result objectAtIndex:0] ObjectForKey:@"success"] isEqualToString:@"Successfully Registered"])
{
LoginViewController *Login=[LoginViewController new];
// In case of NavigatinController u added
[self.navigationController pushViewController:Login animated:YES];
//In case with out NavigatinController
[self presentViewController:Login animated:YES completion:nil];
}
关于ios - 控制台数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27356431/