控制台数据问题

时间:2014-12-08 10:55:50

标签: ios objective-c xcode web-services

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

但是我需要success密钥然后我会打电话给

  if (success==Successfully Registered) {

    LoginViewController *tc=[LoginViewController new];
    [self.navigationController pushViewController:tc animated:YES];

}

我已经尝试了很多方法,但我很困惑,什么时候会得到你能建议我,谢谢@

1 个答案:

答案 0 :(得分:1)

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];

}