[英]perform segue throws error
i have implemented some Json post in objective c and after i received the information i try to push the segue method but it throws this exception我已经在目标 c 中实现了一些 Json 帖子,在我收到信息后,我尝试推送 segue 方法,但它抛出了这个异常
2015-06-25 00:08:33.807 BarApp[1446:109590] -[NSNull length]: unrecognized selector sent to instance 0x37439830 2015-06-25 00:08:33.807 BarApp[1446:109590]-[NSNull 长度]:无法识别的选择器发送到实例 0x37439830
2015-06-25 00:08:33.809 BarApp[1446:109590] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x37439830' 2015-06-25 00:08:33.809 BarApp[1446:109590] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSNull 长度]:无法识别的选择器发送到实例 0x37439830”
and this is my code这是我的代码
-(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"]);
this is where my code breaks up!这是我的代码分解的地方!
[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];
}
}
The message indicates that the length
method was invoked on an NSNull
object.该消息表明已在NSNull
对象上调用了length
方法。 Since the length
method will most likely be invoked on an NSString
因为length
方法很可能会在NSString
上调用
Check this link检查此链接
-[NSNull length]: unrecognized selector sent to JSON objects -[NSNull 长度]:无法识别的选择器发送到 JSON 对象
you should check for [NSNULL null].你应该检查 [NSNULL null]。 You are receiving a or more NSNUll value in your Json request.您在 Json 请求中收到一个或多个 NSNUll 值。
check this may it is yor need- [NSNull isEqualToString:]检查这可能是你需要的 - [NSNull isEqualToString:]
these lines will help you more- NSMutableDictionary *dicAfterRemovingNull = [NSMutableDictionary dictionaryWithDictionary: yourDictionary];这些行将帮助您更多- NSMutableDictionary *dicAfterRemovingNull = [NSMutableDictionary dictionaryWithDictionary: yourDictionary]; // if the dictionary and for array change this line with MutableArray // 如果字典和数组用 MutableArray 改变这一行
for(NSString *key in [dicAfterRemovingNull allKeys])
{
const id object = [dicAfterRemovingNull objectForKey:key];
if(object == [NSNull null])
{
[dicAfterRemovingNull setValue:@"whatever you want" forKey:key];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.