Skip to content

Instantly share code, notes, and snippets.

@descorp
Last active July 13, 2018 13:54
Show Gist options
  • Save descorp/4125892bc3f4e6b6a03c956c2f06b1ba to your computer and use it in GitHub Desktop.
Save descorp/4125892bc3f4e6b6a03c956c2f06b1ba to your computer and use it in GitHub Desktop.
@implementation JsonCleaner
- (NSDictionary*)clearJsonDictionaryFromPrivateProperties:(NSDictionary*)jsonDictionary {
NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithDictionary:jsonDictionary];
for (NSString* key in tempDict.allKeys) {
if ([tempDict[key] isKindOfClass:NSDictionary.class]) {
tempDict[key] = [self clearJsonDictionaryFromPrivateProperties:tempDict[key]];
} else if ([tempDict[key] isKindOfClass:NSArray.class] &&
[tempDict[key][0] isKindOfClass:NSDictionary.class]) {
NSMutableArray *array = [NSMutableArray array];
for (NSDictionary *subDict in tempDict[key]) {
[array addObject:[self clearJsonDictionaryFromPrivateProperties:subDict]];
}
tempDict[key] = array;
} else if ([key hasSuffix:@"_"] || [key hasPrefix:@"_"]) {
[tempDict removeObjectForKey:key];
}
}
return tempDict;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment