docs/docsets/Alamofire.docset/Contents/Resources/Documents/Structs/JSONEncoding.html
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
`
Error produced by JSONEncoding.
Swift
public enum Error : Swift.Error
`
default
`
Returns a JSONEncoding instance with default writing options.
Swift
public static var `default`: JSONEncoding { get }
`
prettyPrinted
`
Returns a JSONEncoding instance with .prettyPrinted writing options.
Swift
public static var prettyPrinted: JSONEncoding { get }
`
options
`
The options for writing the parameters as JSON data.
Swift
public let options: JSONSerialization.WritingOptions
`
init(options:)
`
Creates an instance using the specified WritingOptions.
Swift
public init(options: JSONSerialization.WritingOptions = [])
| options |
JSONSerialization.WritingOptions to use.
|
`
encode(_:with:)
`
Swift
public func encode(_ urlRequest: any URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest
`
encode(_:withJSONObject:)
`
Encodes any JSON compatible object into a URLRequest.
Throws
Any Error produced during encoding.
Swift
public func encode(_ urlRequest: any URLRequestConvertible, withJSONObject jsonObject: Any? = nil) throws -> URLRequest
| urlRequest |
URLRequestConvertible value into which the object will be encoded.
|
| jsonObject |
Any value (must be JSON compatible) to be encoded into the URLRequest. nil by default.
|
The encoded URLRequest.