【问题标题】:AFNetworking/ Overcoat/Promisekit - getting the return json in the error messageAFNetworking/Overcoat/Promisekit - 在错误消息中获取返回 json
【发布时间】:2015-04-24 18:10:22
【问题描述】:

我正在使用 AFNetworking、Overcoat 和 Promisekit。我想查看从服务器返回的 json。

//apiclient.h
@interface STRAPIClient : OVCHTTPSessionManager

//apiclient.m
[self POST:@"contents" parameters:parameters]
    .then(^(OVCResponse *response) {
      return response.result;
    })
    .catch(^(NSError * error){
        NSLog(error.description);
    });;

如何从 NSError 对象中获取响应字符串?

【问题讨论】:

  • 你指的是什么回应?如果错误对应于网络错误,那么您将没有响应。
  • 对不起,我澄清了。我指的是服务器返回的 json 字符串

标签: objective-c promise afnetworking afnetworking-2 promisekit


【解决方案1】:

检查error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey]error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey]

来自AFURLResponseSerialization.h

常量

AFNetworkingOperationFailingURLResponseErrorKey
对应的值是一个NSURLResponse,其中包含与错误相关的操作的响应。此密钥仅存在于AFURLResponseSerializationErrorDomain

AFNetworkingOperationFailingURLResponseDataErrorKey
对应的值是一个NSData,其中包含与错误相关的操作的原始数据。此密钥仅存在于AFURLResponseSerializationErrorDomain

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 2014-05-01
    • 2018-02-18
    相关资源
    最近更新 更多