SwiftyJSON的职责与能力
@(编程笔记)[iOS开发,SwiftyJSON]
SwiftyJSON的职责是提供灵活操作JSON的能力,而不是把它变成一个Object对象。
it's not the role of SwiftyJSON to map JSON to models. SwiftyJSON's role is to allow manipulating json data flexibly, but not map it onto an object. There are a ton of other libraries whose role is to do this, on top of my head: Unbox, ObjectMapper, Mapper, etc. Those are fully unit tested and are doing a much better job at this than what SwiftyJSON would provide.
Unbox and Wrap
而如果想要这么干,Unbox and Wrap 也可以,它们可以把 Arrays 和 Dictionarys 转成 Objects,因此可以很好的与 SwiftyJSON 共存。
Thumbs up for Unbox and Wrap which interoperate nicely with SwiftyJSON. Many of the other object mappers need raw JSON data/strings, but these two work well with the Arrays and Dictionaries that SwiftyJSON emits and ingests. It may be worth a shout out in the README.
Wrap: Swift JSON encoder, encode an instance to JSON: https://github.com/JohnSundell/Wrap
Unbox: Swift JSON decoder, decode JSON to an instance: https://github.com/JohnSundell/Unbox
注
参考资料里“JSON化框架的对比”说 SwiftyJSON 性能不是最优,但是至少在 Github 上这个方案 star 最多。而且我使用的 JSON 数据量比较小,性能因素影响不大。
参考资料
JSON化框架的对比
https://github.com/SwiftyJSON/SwiftyJSON/issues/714
网友评论