后台不知道是哪个坑货写的,接口经常有应该返回空串@""的, 非要返回@"<null>", 写了个方法,纠正数据
递归验证AFN请求的返回数据responseObject
+ (id)getRightData:(id)responseObject {
if ([responseObject isKindOfClass:[NSDictionary class]]) {
responseObject = [NSMutableDictionary dictionaryWithDictionary:responseObject];
for (NSString *key in [responseObject allKeys]) {
responseObject[key] = [self getRightData:responseObject[key]];
}
} else if ([responseObject isKindOfClass:[NSArray class]]) {
responseObject = [NSMutableArray arrayWithArray:responseObject];
for (NSInteger index = 0; index < [responseObject count]; index++) {
responseObject[index] = [self getRightData:responseObject[index]];
}
} else if ([responseObject isKindOfClass:[NSString class]]) {
return [NSString verify:responseObject];
} else if ([responseObject isKindOfClass:[NSNull class]]){
return [NSString verify:responseObject];
}
return responseObject;
}
网友评论