如何检查来自 json 的值是否为 null?
我想检查 json 的结果是否为 null ..我使用了此代码
- (NSString *)likesCount {
if ([facebook valueForKey:@"likes"] == [NSNull null]) {
return @"";
}
else {
return [facebook valueForKey:@"likes"];
}
}
likes = 1
;如果它存在且为 null "like"
在输出中不可见。但如果它不存在,则返回 (null)
..我在上面使用过代码,但它不起作用。
我正在 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];
谢谢
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"];
}
}
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.
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];
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 NSDictionary 上使用这个类别,代码会干净很多:
TouchJSON,处理 NSNull
Use this category on NSDictionary, code will be much cleaner:
TouchJSON, dealing with NSNull
试试这个代码
Try this code