I used below code to replace nulls from json response with empty string, but it is not working. Please help me out to fix this issue, i am getting nulls from server response in lot of scenarios and App crashes.
Code:
- (NSMutableDictionary *)recursive:(NSMutableDictionary *)dictionaryResponse {
NSMutableDictionary *dictionary=[[NSMutableDictionary alloc]initWithDictionary:dictionaryResponse];
for (NSString *key in [dictionary allKeys]) {
id nullString = [dictionary objectForKey:key];
if ([nullString isKindOfClass:[NSDictionary class]]) {
[self recursive:(NSMutableDictionary*)nullString];
}else if([nullString isKindOfClass:[NSArray class]]){
for (int i=0; i<[nullString count]; i++) {
id nullstr = [nullString objectAtIndex:i];
if ([nullstr isKindOfClass:[NSDictionary class]]) {
[self recursive:(NSMutableDictionary*)nullstr];
}
}
}else {
if ((NSString*)nullString == (id)[NSNull null])
[dictionary setValue:@"" forKey:key];
}
}
return dictionary;
}
try this:
EDITED:
I hase find the problem in my answer, and now it fixed
this is check code:
here is simple method to remove the Null from the string