Open datoujiejie opened 5 years ago
CTApiProxy中 NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:&error]; 如果上面返回的error是nil,对error取地址的话是有值的 接下来Demoservice中,提前返回了,造成请求成功时kCTApiProxyValidateResultKeyResponseObject里面的值为空,后面的请求结果拿不到值
NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:&error];
`- (NSDictionary )resultWithResponseObject:(id)responseObject response:(NSURLResponse )response request:(NSURLRequest *)request error:(NSError *)error { NSMutableDictionary result = [[NSMutableDictionary alloc] init]; if (error || !responseObject) { return result; }
if ([responseObject isKindOfClass:[NSData class]]) { result[kCTApiProxyValidateResultKeyResponseString] = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; result[kCTApiProxyValidateResultKeyResponseObject] = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:NULL]; } else { //这里的kCTApiProxyValidateResultKeyResponseString是用作打印日志用的,实际使用时可以把实际类型的对象转换成string用于日志打印
// result[kCTApiProxyValidateResultKeyResponseString] = responseObject; result[kCTApiProxyValidateResultKeyResponseObject] = responseObject; }
return result;
}`
既然error是用于判断的,就不要写成 error:(NSError **)error这种形式,建议修改如下
NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:error]; - (NSDictionary *)resultWithResponseObject:(id)responseObject response:(NSURLResponse *)response request:(NSURLRequest *)request error:(NSError *)error
NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:error];
- (NSDictionary *)resultWithResponseObject:(id)responseObject response:(NSURLResponse *)response request:(NSURLRequest *)request error:(NSError *)error
这个地方的逻辑有问题,要么直接传入error,然后用error做判断 如果要传入&error,那么做判断的时候用*error来做判断
CTApiProxy中
NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:&error];
如果上面返回的error是nil,对error取地址的话是有值的 接下来Demoservice中,提前返回了,造成请求成功时kCTApiProxyValidateResultKeyResponseObject里面的值为空,后面的请求结果拿不到值`- (NSDictionary )resultWithResponseObject:(id)responseObject response:(NSURLResponse )response request:(NSURLRequest *)request error:(NSError *)error { NSMutableDictionary result = [[NSMutableDictionary alloc] init]; if (error || !responseObject) { return result; }
// result[kCTApiProxyValidateResultKeyResponseString] = responseObject; result[kCTApiProxyValidateResultKeyResponseObject] = responseObject; }
}`
既然error是用于判断的,就不要写成 error:(NSError **)error这种形式,建议修改如下
NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:error];
- (NSDictionary *)resultWithResponseObject:(id)responseObject response:(NSURLResponse *)response request:(NSURLRequest *)request error:(NSError *)error