Is there a way to register custom accept headers to parse as JSON in AFNetworking 1.3?

StackOverflow https://stackoverflow.com/questions/23257398

  •  08-07-2023
  •  | 
  •  

سؤال

I have a server that is sending back JSON using the following accept header:

[self setDefaultHeader:@"Accept" value:@"application/vnd.com.test.v1+json"];

In the success block of the API calls, the response data is coming back as a NSData object.

I read in the following question Issue with retrieving JSON with AFNetworking that I need to set @"application/json" if I want JSON to be parsed into an NSDictionary automatically, otherwise I have to manually do it for each call using NSJSONSerialization.

Is there a way that I can get @"application/vnd.com.test.v1+json" to be recognized as JSON and automatically do JSON deserialization for each request?

هل كانت مفيدة؟

المحلول

Add your desired content types to AFHTTPRequestOperation using addAcceptableContentTypes::

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/vnd.com.test.v1+json"];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top