开发者网址导航

iOS中将JSON直接转成实体类文件

Tang Tang    ·  111 浏览

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
    }

}
0个回答
恭喜你,这是一条成功消息
!
警告哦,这是一条警告消息