Deserialize JSON / NSDictionary to Swift objects

前端 未结 13 1515
情歌与酒
情歌与酒 2020-11-29 18:43

Is there a way to properly deserialize a JSON response to Swift objects resp. using DTOs as containers for fixed JSON APIs?

Something similar to http://james.newtonk

13条回答
  •  抹茶落季
    2020-11-29 19:07

    If you would like parse from and to json without the need to manually map keys and fields, then you could also use EVReflection. You can then use code like:

    var user:User = User(json:jsonString)
    

    or

    var jsonString:String = user.toJsonString()
    

    The only thing you need to do is to use EVObject as your data objects base class. See the GitHub page for more detailed sample code

提交回复
热议问题