afnetworking 3 - Not able to parse response in JSON response -
i using afnetworking 3, xcode 7.2 ios 9.
afurlsessionmanager *ses = [[afurlsessionmanager alloc] initwithsessionconfiguration:[nsurlsessionconfiguration defaultsessionconfiguration]]; ses.responseserializer = [afjsonresponseserializer serializer]; //request [[afjsonrequestserializer serializer] setvalue:@"application/json" forhttpheaderfield:@"accept"]; nsmutableurlrequest *request = [[afjsonrequestserializer serializer] requestwithmethod:@"get" urlstring:endpoint parameters:parameters error:nil]; nsurlsessiondatatask *datatask = [ses datataskwithrequest:request completionhandler:^(nsurlresponse *response, id responseobject, nserror *error) { if (error) { nslog(@"error: %@", error); } else { nslog(@"%@ %@", response, responseobject); } }]; [datatask resume];
but getting error response as:
domain=com.alamofire.error.serialization.response code=-1016 "request failed: unacceptable content-type: text/plain"
the request content type still set "text/plain" not sure missing .
i used http response serializer , worked fine.
afurlsessionmanager *ses = [[afurlsessionmanager alloc] initwithsessionconfiguration:[nsurlsessionconfiguration defaultsessionconfiguration]]; ses.responseserializer = [afhttpresponseserializer serializer]; nsmutabledictionary * innerjson = [nsjsonserialization jsonobjectwithdata:responseobject options:kniloptions error:&error1];
Comments
Post a Comment