本文介绍了如何检查来自json的值是否为null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查json的结果是否为null ..我使用此代码
I want to check result of json is null or not ..I used this code
- (NSString *)likesCount { if ([facebook valueForKey:@"likes"] == [NSNull null]) { return @""; } else { return [facebook valueForKey:@"likes"]; } }赞= 1 ;如果它存在并且它是null like在输出中不可见..但是如果它不存在那么它返回(null) ..我使用上面的代码,但它不起作用。
likes = 1; if it exists and if it is null "like" is not visible in output.. But if it is not present then it is returning (null) .. I used above code but it is not working.
我在UItableviewcell中打印这个喜欢的值
I am printing this value of likes in UItableviewcell
UILabel *commentLike = [[UILabel alloc] initWithFrame:CGRectMake(200, 70, 100, 20)]; commentLike.font = [UIFont fontWithName:@"Arial" size:10.0]; NSString *commentLikeString = [NSString stringWithFormat:@"%@ ",[(Facebook *)[tableArray objectAtIndex:indexPath.row]likesCount]]; commentLike.text = [NSString stringWithFormat:@"%@ Person"]; [cell.contentView addSubview:commentLike];谢谢
推荐答案在NSDictionary上使用此类别,代码将更清晰:
Use this category on NSDictionary, code will be much cleaner:
TouchJSON,处理NSNull
更多推荐
如何检查来自json的值是否为null?
发布评论