JSONCoder
public final class JSONCoder
Converts between JSON
and other Codable
types.
-
Converts an
Encodable
type to aJSON
instanceThrows
Encoding errors that occur when encoding the
Encoodable
type toJSON
.Declaration
Swift
public static func encode<T>(_ t: T) throws -> JSON where T : Encodable
Parameters
t
The
Encodable
value to convert.Return Value
The
JSON
that represents theEncodable
value. -
Converts a
JSON
instance to aDecoable
type.Throws
Decoding errors that occur when decoding
JSON
toT
.Declaration
Swift
public static func decode<T>(_ type: T.Type, from json: JSON) throws -> T where T : Decodable
Parameters
type
The
Decodable
type to create from theJSON
.json
The
JSON
instance to convert to typeT
.Return Value
An instance of
T
created from theJSON
instance passed in.