JSONModel

public protocol JSONModel : AnyModel, _ExtendCustomModelType

通用JSON模型协议,默认未实现KeyMappable,使用方式同HandyJSON(不推荐,直接读写内存模式,不稳定也不安全); JSONModel可实现KeyMappable,并选择以下模式使用,推荐方式

KeyMappable模式一:MappedValue模式

  1. 支持JSONModel类型字段,使用方式:@MappedValue
  2. 支持多字段映射,使用方式:@MappedValue(“name1”, “name2”)
  3. 支持Any类型字段,使用方式:@MappedValue
  4. 未标记MappedValue的字段将自动忽略,也可代码忽略:@MappedValue(ignored: true)

KeyMappable模式二:MappedValueMacro模式(需引入FWMacro子模块)

  1. 标记class或struct为自动映射存储属性宏,使用方式:@MappedValueMacro
  2. 可自定义字段映射规则,使用方式:@MappedValue(“name1”, “name2”)
  3. 以下划线开头或结尾的字段将自动忽略,也可代码忽略:@MappedValue(ignored: true)

KeyMappable模式三:自定义模式

  1. 需完整实现JSONModel协议的mappingValue(_:forKey:)协议方法

HandyJSON

Deserializer

  • Finds the internal dictionary in dict as the designatedPath specified, and converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func deserialize(from dict: [AnyHashable : Any]?, designatedPath: String? = nil) -> Self?
  • Finds the internal JSON field in json as the designatedPath specified, and converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func deserialize(from json: String?, designatedPath: String? = nil) -> Self?
  • Finds the internal JSON field in array as the designatedPath specified, and converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func deserialize(from array: [Any]?, designatedPath: String? = nil) -> Self?
  • Finds the internal JSON field in object as the designatedPath specified, and converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func deserializeAny(from object: Any?, designatedPath: String? = nil) -> Self?
  • Finds the internal dictionary in dict as the designatedPath specified, and safe converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func safeDeserialize(from dict: [AnyHashable : Any]?, designatedPath: String? = nil) -> Self
  • Finds the internal JSON field in json as the designatedPath specified, and safe converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func safeDeserialize(from string: String?, designatedPath: String? = nil) -> Self
  • Finds the internal JSON field in array as the designatedPath specified, and safe converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func safeDeserialize(from array: [Any]?, designatedPath: String? = nil) -> Self
  • Finds the internal JSON field in object as the designatedPath specified, and safe converts it to a Model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer

    Declaration

    Swift

    static func safeDeserializeAny(from object: Any?, designatedPath: String? = nil) -> Self
  • merge(from:designatedPath:) Extension method

    Finds the internal dictionary in dict as the designatedPath specified, and use it to reassign an exist model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer, or nil

    Declaration

    Swift

    mutating func merge(from dict: [AnyHashable : Any]?, designatedPath: String? = nil)
  • merge(from:designatedPath:) Extension method

    Finds the internal JSON field in json as the designatedPath specified, and use it to reassign an exist model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer, or nil

    Declaration

    Swift

    mutating func merge(from string: String?, designatedPath: String? = nil)
  • merge(from:designatedPath:) Extension method

    Finds the internal JSON field in array as the designatedPath specified, and use it to reassign an exist model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer, or nil

    Declaration

    Swift

    mutating func merge(from array: [Any]?, designatedPath: String? = nil)
  • Finds the internal JSON field in object as the designatedPath specified, and use it to reassign an exist model designatedPath is a string like result.data.orderInfo, which each element split by . represents key of each layer, or nil

    Declaration

    Swift

    mutating func mergeAny(from object: Any?, designatedPath: String? = nil)

Serializer

  • toJSON() Extension method

    Undocumented

    Declaration

    Swift

    func toJSON() -> [String : Any]?
  • toJSONString(prettyPrint:) Extension method

    Undocumented

    Declaration

    Swift

    func toJSONString(prettyPrint: Bool = false) -> String?

Available where Self: AnyObject

  • hashString Extension method

    Undocumented

    Declaration

    Swift

    var hashString: String { get }