我正在使用 AFNetworking 从服务器获取 JSON。我的问题是,如果会话过期,服务器会回复字符串“NOSESSION”。
这是我的代码:
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success: ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
NSArray *jsonArray =[JSON valueForKey:@"posts"];
//DOING SOMETHING WITH jsonArray
// in case that the response is NOSESSION do something
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
}];
[operation start];
我的问题是这是请求失败,因为响应不是字符串。错误信息:
Failed Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.)
有没有办法知道响应字符串?(我不介意在失败中捕获它我只想知道会话何时过期)