2015-06-25 177 views
2

我已经实现的目标C的Json一些后,我收到的信息后,我试着推SEGUE方法,但它引发此异常执行SEGUE抛出错误

2015年6月25日00:08:33.807 BarApp [1446:109590] - [NSNull length]:无法识别的选择器发送到实例0x37439830

2015-06-25 00:08:33.809 BarApp [1446:109590] ***由于未捕获的异常'NSInvalidArgumentException' ,原因:' - [NSNull长度]:无法识别的选择器发送到实例0x37439830'

,这是我的代码

-(void) MakePost: (int)typePost { 
    NSString *mainUrl = @"http://url.com/barap/usuario.php"; 
    NSString *post; 

    if(typePost == 0) { 
     post = [NSString stringWithFormat:@"?type=0&email=%@&password=%@",self.emailTextField.text, self.passwordTextField.text]; 
    }else if(typePost == 1){ 
     post = [NSString stringWithFormat:@"?type=1&fb_id=%@&nombre=%@&apellido_m=%@&email=%@&profile_picture=%@",fb_id, nombre, apellidoM, email, profilePictureUrl]; 
    } 

    NSString *webPostUrl = [NSString stringWithFormat:@"%@%@", mainUrl, post]; 
    webPostUrl =[webPostUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSURL *postUrl = [NSURL URLWithString:webPostUrl]; 
    NSData *userInfo = [[NSData alloc] initWithContentsOfURL:postUrl]; 

    if(userInfo){ 
     NSMutableDictionary *userResults = [NSJSONSerialization JSONObjectWithData:userInfo options:NSJSONReadingMutableContainers error:nil]; 
     if (![userResults[@"id"] isEqualToString:@""]) { 
      [defaults setObject:userResults[@"id"] forKey:@"userId"]; 
      NSLog(@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"userId"]); 

这是我的代码打破了!

[self performSegueWithIdentifier:@"loginSuccess" sender:self]; 


      if(typePost == 1){ 
       [FBSDKAccessToken setCurrentAccessToken:nil]; 
       [FBSDKProfile setCurrentProfile:nil]; 
      } 
     } 
    }else { 
     UIAlertView* cError = [[UIAlertView alloc]initWithTitle:@"Erro!" message:@"Tuvimos un Error intente mas tarde" delegate:self cancelButtonTitle:@"Cancelar" otherButtonTitles:@"OK", nil]; 
     [cError show]; 
    } 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if([[segue identifier] isEqualToString:@"loginSuccess"]) { 
     [segue destinationViewController]; 
    } 
} 

回答

1

您应该检查[NSNULL null]。您在Json请求中收到一个或多个NSNUll值。

检查这可能是侑需要 - [NSNull isEqualToString:]

这些行会帮助你更多 - 的NSMutableDictionary * dicAfterRemovingNull =的NSMutableDictionary dictionaryWithDictionary:yourDictionary]。 //如果字典和用于阵列改变这一行与MutableArray

for(NSString *key in [dicAfterRemovingNull allKeys]) 
{ 
    const id object = [dicAfterRemovingNull objectForKey:key]; 
    if(object == [NSNull null]) 
    { 
     [dicAfterRemovingNull setValue:@"whatever you want" forKey:key]; 
    } 
}