JSONEncoding
public struct JSONEncoding : ParameterEncoding
Uses JSONSerialization to create a JSON representation of the parameters object, which is set as the body of the
request. The Content-Type HTTP header field of an encoded request is set to application/json.
-
Error produced by
See moreJSONEncoding.Declaration
Swift
public enum Error : Swift.Error
-
Returns a
JSONEncodinginstance with default writing options.Declaration
Swift
public static var `default`: JSONEncoding { get } -
Returns a
JSONEncodinginstance with.prettyPrintedwriting options.Declaration
Swift
public static var prettyPrinted: JSONEncoding { get } -
The options for writing the parameters as JSON data.
Declaration
Swift
public let options: JSONSerialization.WritingOptions
-
Creates an instance using the specified
WritingOptions.Declaration
Swift
public init(options: JSONSerialization.WritingOptions = [])Parameters
optionsJSONSerialization.WritingOptionsto use.
-
Declaration
Swift
public func encode(_ urlRequest: any URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest -
Encodes any JSON compatible object into a
URLRequest.Throws
Any
Errorproduced during encoding.Declaration
Swift
public func encode(_ urlRequest: any URLRequestConvertible, withJSONObject jsonObject: Any? = nil) throws -> URLRequestParameters
urlRequestURLRequestConvertiblevalue into which the object will be encoded.jsonObjectAnyvalue (must be JSON compatible) to be encoded into theURLRequest.nilby default.Return Value
The encoded
URLRequest.
View on GitHub
Install in Dash