DataDecodingStrategy
The strategy to use for decoding Data
values.
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
enum DataDecodingStrategy
The strategy to use for decoding Data
values.
enum DataDecodingStrategy
s20FoundationEssentials11JSONDecoderC20DataDecodingStrategyO
What are these?2NBR1
import FoundationEssentials
class JSONDecoder
JSONDecoder
facilitates the decoding of JSON into semantic Decodable
types.
case base64
Decode the Data
from a Base64-encoded string. This is the default strategy.
@preconcurrency case custom((any Decoder) throws -> Data)
Decode the Data
as a custom value decoded by the given closure.
case deferredToData
Defer to Data
for decoding.
init()
Initializes self
with default strategies.
var allowsJSON5: Bool { get set }
Set to true
to allow parsing of JSON5. Defaults to false
.
var assumesTopLevelDictionary: Bool { get set }
Set to true
to assume the data is a top level Dictionary (no surrounding “{ }” required). Defaults to false
. Compatible with both JSON5 and non-JSON5 mode.
var dataDecodingStrategy: JSONDecoder.DataDecodingStrategy { get set }
The strategy to use in decoding binary data. Defaults to .base64
.
var dateDecodingStrategy: JSONDecoder.DateDecodingStrategy { get set }
The strategy to use in decoding dates. Defaults to .deferredToDate
.
var keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy { get set }
The strategy to use for decoding keys. Defaults to .useDefaultKeys
.
var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy { get set }
The strategy to use in decoding non-conforming numbers. Defaults to .throw
.
var userInfo: [CodingUserInfoKey : Any] { get set }
Contextual user-provided information for use during decoding.
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable
Decodes a top-level value of the given type from the given JSON representation.
func decode<T>(_ type: T.Type, from data: Data, configuration: T.DecodingConfiguration) throws -> T where T : DecodableWithConfiguration
func decode<T, C>(_ type: T.Type, from data: Data, configuration: C.Type) throws -> T where T : DecodableWithConfiguration, C : DecodingConfigurationProviding, T.DecodingConfiguration == C.DecodingConfiguration
enum DateDecodingStrategy
The strategy to use for decoding Date
values.
enum KeyDecodingStrategy
The strategy to use for automatically changing the value of keys before decoding.
enum NonConformingFloatDecodingStrategy
The strategy to use for non-JSON-conforming floating-point values (IEEE 754 infinity and NaN).
protocol Sendable