JSONDecoder

extension JSONDecoder
  • Decodes a value of the given type for the given keypath from the JSON object.

    Throws

    An Error if the decoding process encounters an error.

    Declaration

    Swift

    public func decode<T>(_ type: T.Type, from data: Data, keyPath: String) throws -> T where T : Decodable

    Parameters

    type

    The type of value to decode.

    data

    The JSON object to decode.

    keyPath

    The key path of the decoded value is associated with.

    Return Value

    A decoded value of the requested type.

  • Decodes a value of the given type for the given keypath from the JSON object and also a decoded ListInfo if the given type is an array with a list info JSON object.

    Throws

    An Error if the decoding process encounters an error.

    Declaration

    Swift

    public func decodeWithListInfo<T: Decodable>(_ type: T.Type,
                                                 from data: Data,
                                                 keyPath: String) throws -> (model: T, listInfo: ListInfo?)

    Parameters

    type

    The type of value to decode.

    data

    The JSON object to decode.

    keyPath

    The key path of the decoded value is associated with.

    Return Value

    A tuple containing the decoded value of the requested type as the model, and an optional ListInfo.