swift4.0 建立模型,json转模型
建立模型Barrage,继承自Codable struct Barrage : Codable { let avatarUrl : String? let data : BarrageData? let time : Int? let type : Int? let userId : Int? let username : String? } 把数据转成model,使用swift自带的转模型的方法。真没想到,swift居然可以如此简便。 let model = try JSONDecoder().decode(T.self, from: json)
