", 写了个方法,纠正数据递归...">
美文网首页
iOS递归校验数据验证,去除坑爹的<null>

iOS递归校验数据验证,去除坑爹的<null>

作者: yiangdea | 来源:发表于2018-05-03 17:19 被阅读37次

    后台不知道是哪个坑货写的,接口经常有应该返回空串@""的, 非要返回@"<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;
    }
    

    相关文章

      网友评论

          本文标题:iOS递归校验数据验证,去除坑爹的<null>

          本文链接:https://www.haomeiwen.com/subject/pzrlrftx.html