Back to Alamofire

JSONResponseSerializer

docs/Classes/JSONResponseSerializer.html

5.12.02.8 KB
Original Source

JSONResponseSerializer

@available(*, deprecated, message: "JSONResponseSerializer deprecated and will be removed in Alamofire 6. Use DecodableResponseSerializer instead.")
public final class JSONResponseSerializer : ResponseSerializer

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 request has an HTTPMethod or the response has an HTTP status code valid for empty responses, then an NSNull value is returned.

Note

This serializer is deprecated and should not be used. Instead, create concrete types conforming to Decodable and use a DecodableResponseSerializer.

`

                dataPreprocessor
                `

Declaration

Swift

public let dataPreprocessor: any DataPreprocessor

`

                emptyResponseCodes
                `

Declaration

Swift

public let emptyResponseCodes: Set<Int>

`

                emptyRequestMethods
                `

Declaration

Swift

public let emptyRequestMethods: Set<HTTPMethod>

`

                options
                `

JSONSerialization.ReadingOptions used when serializing a response.

Declaration

Swift

public let options: JSONSerialization.ReadingOptions

`

                init(dataPreprocessor:emptyResponseCodes:emptyRequestMethods:options:)
                `

Creates an instance with the provided values.

Declaration

Swift

public init(dataPreprocessor: any DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor,
            emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes,
            emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods,
            options: JSONSerialization.ReadingOptions = .allowFragments)

Parameters

| dataPreprocessor |

DataPreprocessor used to prepare the received Data for 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. .allowFragments by default.

|

`

                serialize(request:response:data:error:)
                `

Declaration

Swift

public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: (any Error)?) throws -> Any