1.解析后获得的字典调用此方法,会返回一个新的处理好的字典
2.新的字典里所有的null对象被替换为@""
3.也可以在此方法中做别的处理(比如说把NSValue对象也统一转化为字符串)
4.github地址 https://github.com/wangyebin
上代码
#import "NSObject+WYBExtension.h"
@implementation NSObject (WYBExtension)
//NUll处理;
- (id)checkTheDic
{
if ([self isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary * myDic = [[NSMutableDictionary alloc]initWithDictionary:(NSDictionary *)self];
NSArray * array = myDic.allKeys;
for (int i = 0; i < array.count; i++) {
id Object = myDic[array[i]];
[myDic setObject:[Object checkTheDic] forKey:array[i]];
}
return myDic;
} else if ([self isKindOfClass:[NSArray class]]){
NSArray * array = (NSArray *)self;
NSMutableArray * muArray = [[NSMutableArray alloc]initWithCapacity:100];
for (int i = 0;i < array.count ; i++) {
[muArray addObject:[array[i] checkTheDic]];
}
return muArray;
} else if ([self isKindOfClass:[NSNull class]]) {
return @"";
} else {
return self;
}
}
原创: 转载请注明出处http://www.jianshu.com/p/221b2966b279
网友评论