AFNetworking 2.0 AFHTTPSessionManager: how to get status code and response JSON in failure block?

后端 未结 7 809
你的背包
你的背包 2020-12-04 10:08

When switched to AFNetworking 2.0 the AFHTTPClient has been replaced by AFHTTPRequestOperationManager / AFHTTPSessionManager (as mentioned in the migration guide). The very

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 10:47

    You can access the “data” object directly from AFNetworking by using the “AFNetworkingOperationFailingURLResponseDataErrorKey” key so there is no need for subclassing the AFJSONResponseSerializer. You can the serialize the data into a readable dictionary. Here is some sample code :

     NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
     NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
    

提交回复
热议问题