JSONError

public enum JSONError: Error

A type representing JSON parsing and deserialization errors.

  • The JSON appears to be invalid.

    • underlyingError: the error thrown by JSONSerialization.jsonObject(with:options:).

    Declaration

    Swift

    case invalidJSON(underlyingError: NSError)
  • The String could not be encoded in UTF-8.

    • string: the string that caused the error.

    Declaration

    Swift

    case invalidUTF8String(string: String)
  • The deserializer encountered an unexpected value.

    • cause: the reason the value is invalid.

    Declaration

    Swift

    case invalidValue(cause: String)
  • A value required by the deserializer was missing.

    • name: the name of the missing value.

    Declaration

    Swift

    case missingValue(name: String)
  • The deserializer encountered an unexpected type.

    • type: the type found.
    • whenDeserializing: the type we were deserializing.

    Declaration

    Swift

    case unexpectedType(type: String, whenDeserializing: String)
  • Convert this JSONError into an NSError.

    Note

    The NSError‘s code is one of JSONErrorCode.

    Note

    The NSError’s localizedDescription will always be a human readable english.

    Note

    For invalidJSON, the userInfo also has a value for NSUnderlyingErrorKey.

    Declaration

    Swift

    public func toNSError() -> NSError

    Return Value

    An NSError corresponding to self.