JSONResponseSerializer - SwiftDocOrg/Alamofire GitHub Wiki
A ResponseSerializer that decodes the response data using JSONSerialization. By default, a request returning
nil or no data is considered an error. However, if the response is has a status code valid for empty responses
(204, 205), then an NSNull value is returned.
public final class JSONResponseSerializer: ResponseSerializerCreates an instance with the provided values.
public init(dataPreprocessor: DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor, emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods, options: JSONSerialization.ReadingOptions = .allowFragments)- dataPreprocessor:
DataPreprocessorused to prepare the receivedDatafor serialization. - emptyResponseCodes: The HTTP response codes for which empty responses are allowed.
[204, 205]by default. - emptyRequestMethods: The HTTP request methods for which empty responses are allowed.
[.head]by default. - options: The options to use.
.allowFragmentsby default.
let dataPreprocessor: DataPreprocessorlet emptyResponseCodes: Set<Int>let emptyRequestMethods: Set<HTTPMethod>JSONSerialization.ReadingOptions used when serializing a response.
let options: JSONSerialization.ReadingOptionspublic func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) throws -> Any