gpt4 book ai didi

ios - AFJSONRequestOperation 在 200 response.statusCode 上命中失败 block

转载 作者:行者123 更新时间:2023-11-29 03:39:00 24 4
gpt4 key购买 nike

我的 AFJSONRequestOperation 在 200 响应上遇到故障 block 。这是因为我有额外的 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'}

为什么会这样?

最佳答案

根据我的经验,您需要满足 3 个条件才能成功:

  1. 200响应代码
  2. 响应中包含适当的JSON对象
  3. 响应的 Content-Type 设置为 application/json

希望对您有所帮助。

关于ios - AFJSONRequestOperation 在 200 response.statusCode 上命中失败 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18730907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com