Last active
July 13, 2018 13:54
-
-
Save descorp/4125892bc3f4e6b6a03c956c2f06b1ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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