我的AFJSONRequestOperation正在响应200响应的失败阻止。这是因为我有额外的JSON吗?
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *d = (NSDictionary *)responseObject;
bool required = [d[@"payment_required"] boolValue];
[self.delegate paymentRequired:required];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
int statusCode = operation.response.statusCode;
NSLog(@"status code: %d response: %@", statusCode, operation.responseString);
if (operation.response.statusCode == 402) {
[self.delegate paymentRequired:true];
return ;
}
[self handleOperationFailed:operation action:^{
[self determinePaymentRequired];
}];
}];
在控制台中产生
status code: 200 response: {'payment_required':'false'}
为什么会这样?
答案 0 :(得分:1)
根据我的经验,您需要遇到3个条件才能成功阻止:
希望这可以帮到你。
答案 1 :(得分:0)
您的JSON无效。它有单引号({'payment_required':'false'}
),但JSON格式需要它们是双引号:
{
"payment_required" : false
}
PS:我还删除了false
上的引号,因为false
是有效值(并且是首选)。