responseString
当服务器无法发送有效的 JSON 响应(fe. php 回显一些临时变量或出现问题)时,我遇到了困难。我是这样使用AFJSONRequestOperation
的AFNetwoking
:
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject) {
NSLog(@"object: %@", responseObject);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseString) {
NSLog(@"failure: %@", responseString);
}
];
responseString
是万一失败总是nil
。当我尝试阅读文档时(http://cocoadocs.org/docsets/AFNetworking/1.3.1/Classes/AFJSONRequestOperation.html#//api/name/JSONRequestOperationWithRequest:success:failure :) 我发现有写到失败有三个参数(但实际上是四个,第四个始终为零)。在这种情况下,有什么简单的方法可以将响应作为字符串获取吗?