SmartCodable is a data parsing library based on Codable. It is simple to use, with robust compatibility being one of its main features. SmartCodable 是基于Codable实现的数据解析库。简单易用,强悍的兼容性是SmartCodable的主要特点。 表层API和功能几乎和HandyJSON一致,支持快速的迁移。
fileprivate let jsonStr = """
{
"username": "yuhanle",
"age": "18",
"weight": 65.4,
"sex": 1,
"location": "Toronto, Canada",
}
"""
// 模型定义
struct ZJSmartCodableModel: SmartCodable {
var username: String?
var age: Int?
var weight: Double?
var sex: Int?
var location: String?
}
//模型解析
let people = ZJSmartCodableModel.deserialize(from: jsonStr)!
解析后错误提示
======================== [Smart Decoding Log] ========================
ZJSmartCodableModel 👈🏻 👀
|- age: Expected to decode Int but found a string instead.
=========================================================================
解析后错误提示
使用版本 4.0.3和4.0.4 都是一样的结果