开发者

How to check value is coming from json is null or not?

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


Use this category on NSDictionary, code will be much cleaner:

TouchJSON, dealing with NSNull


Try this code

- (NSString *)likesCount {
    if ([[facebook valueForKey:@"likes"] isEqualToString:@"(null)"] || [facebook valueForKey:@"likes"] == nil) {

        return @"";
    }
    else {

    return [facebook valueForKey:@"likes"];

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜