ios - 控制台数据问题

标签 ios objective-c xcode web-services

我正在我的应用程序中开发注册表单,这里总数据已成功插入到数据库我得到状态也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/

相关文章:

objective-c - Swift 到 pod 内的 Obj-c

iphone - Xcode 3.1.3 - Organizer 设备未激活。请使用 iTunes 激活

ios - 创建一个可以触发两个 Action 并更改其标题的按钮?

swift - 将 JSON 的字符串表示形式转换为 JSON

ios - 如何本地化我的 UITabBarItems?

ios - 如果XIB中有更多顶级 View ,为什么outlet会变成nil

ios - Xcode 应用程序运行问题

ios - Swift 3 核心数据 NSExpression 始终返回 0

ios - 在 iOS 中的自定义 View 中播放视频

objective-c - NSTextFieldCell 或仅带有垂直文本(和彩色着色)的 NSCell