适用于 iOS 的 REST API 的良好序列化格式?
通常,对于 REST API,我会使用 JSON 作为输出序列化格式,但我想知道考虑到资源更加受限的环境,这是否仍然是 iOS 开发(特别是 iPad)的绝佳选择。
有各种可用于 iOS 的 JSON 和 XML 库,但是是否有一些最佳实践,或者采用其中一种方式的原因?
或者考虑到 plist 编码/解码看起来像是内置在 iOS 中,使用 plist 格式的 XML 会更好吗?
Normally for REST APIs I'd use JSON as the output serialization format, but I'm wondering if that's still a great choice for iOS development (specifically, the iPad) given the more resource-constrained environment.
There are various JSON and XML libraries available for iOS, but are there some best practices for this, or reasons to go one way or the other?
Or would it be better to use XML in plist format, given that plist encoding/decoding looks like it's built into iOS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iOS 通常更喜欢 PLIST 中的 XML /Bundle 格式。
然而,这本质上并不是特别轻量级,并且肯定不是普遍可读的(如果您决定扩展到非 Apple 环境)。对于 iOS 来说,JSON 仍然是一个不错的选择,使用 SBJSON 框架等库。
因此,这实际上取决于您希望与 iOS/Mac 操作系统的联系程度。这两个选项都很容易处理。
iOS generally prefers XML in a PLIST/Bundle format.
However, this is not particularly lightweight in nature, and is certainly not universally legible (should you decide to expand into non-Apple environments). JSON is still a great option for iOS, using the libraries like the SBJSON framework.
So it really depends on how tethered to iOS/Mac OS you'd like to be. Both options are reasobly simple to deal with.
似乎只有二进制 plist 格式才会带来性能优势,而使用二进制格式有很多缺点。即便如此,JSONKit 库也比 Apple 内置的二进制 plist 解析器快几倍。这是回答我所有问题的文章:
JSON 与 PLIST,终极对决
所以我想我会坚持使用 JSON,并且可能会选择 JSONKit。
It seems that only the binary plist format will give any performance advantages, and there are many disadvantages to using a binary format. Even then, the JSONKit library is several times faster than Apple's built-in binary plist parser. Here's the article that answered all my questions:
JSON versus PLIST, the Ultimate Showdown
So I think I'll stick with JSON and probably go for JSONKit.