如何检查来自json的值是否为null?

编程入门 行业动态 更新时间:2024-10-10 08:25:33
本文介绍了如何检查来自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?

本文发布于:2023-11-09 11:46:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:json   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!