iOS中将JSON直接转成实体类文件
https://github.com/hkellaway/Gloss
代码示意:
JSON
{
"id" : 5456481,
"login" : "hkellaway"
}
Model
import Gloss
struct RepoOwner: Decodable {
let ownerId: Int?
let username: String?
// MARK: - Deserialization
init?(json: JSON) {
self.ownerId = "id" <~~ json
self.username = "login" <~~ json
}
}