首页 > 其他 > 详细

检查字典中是否有NULL 类型,如果有的话,转换成"",因为字典中又null ,是不能存入到NSUserDefalut 里面的.

时间:2015-03-13 15:46:59      阅读:454      评论:0      收藏:0      [点我收藏+]

//该方法是检查字典中是否有nil 的,有nil就转行成""

- (NSDictionary *)checkDict:(NSDictionary *)sender

{

    NSMutableDictionary * dict_mutable = [[NSMutableDictionary alloc] init];

    NSArray * keys = sender.allKeys;

    for (NSString * key in keys) {

        if ([[sender objectForKey:key] isKindOfClass:[NSDictionary class]]) {

             NSDictionary * tempDict = [self checkDict:[sender objectForKey:key]];

            [dict_mutable setObject:tempDict forKey:key];

        }

        else{

            if ([[sender objectForKey:key] isKindOfClass:[[NSNull null] class]]) {

                [dict_mutable setObject:@"" forKey:key];

            }

            else{

                [dict_mutable setObject:[sender objectForKey:key] forKey:key];

            }

        }

    }

    return dict_mutable;

}

检查字典中是否有NULL 类型,如果有的话,转换成"",因为字典中又null ,是不能存入到NSUserDefalut 里面的.

原文:http://www.cnblogs.com/yinyakun/p/4335020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!