如何在故障块内调用的NSURLSessionDataTask中访问服务器的响应?

时间:2015-12-15 09:26:15

标签: ios swift afnetworking

现在调用AFNetworking的{​​{1}}方法中的失败块。并且可以访问POST

我需要从服务器访问响应。我希望字典像这样:

NSURLSessionDataTask

但我不知道在哪里寻找这个?可以使用{ "error": "sth written on the backend" } AFHTTPRequestOperation

使用 AFNetworking 3.0

示例:

AFNetworking 2.0

1 个答案:

答案 0 :(得分:0)

所有内容都包含在if let responseData = error?.userInfo[NSString(string: AFNetworkingOperationFailingURLResponseDataErrorKey)] as? NSData { do { if let response = try NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.AllowFragments) as? [String: AnyObject] { //do sth with your response } } catch { //handle the exception } } 对象中:

{{1}}