I have a JSON object that is coming from a webserver.
The log is something like this:
{
\"status\":\"success\",
\"Us
If you are dealing with an "unstable" API, you may want to iterate through all the keys to check for null. I created a category to deal with this:
@interface NSDictionary (Safe)
-(NSDictionary *)removeNullValues;
@end
@implementation NSDictionary (Safe)
-(NSDictionary *)removeNullValues
{
NSMutableDictionary *mutDictionary = [self mutableCopy];
NSMutableArray *keysToDelete = [NSMutableArray array];
[mutDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if (obj == [NSNull null])
{
[keysToDelete addObject:key];
}
}];
[mutDictinary removeObjectsForKeys:keysToDelete];
return [mutDictinary copy];
}
@end