iOS 中的原生 JSON 支持?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3562478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:36:25  来源:igfitidea点击:

Native JSON support in iOS?

iphonejsonparsingobjectios

提问by Moshe

Is there a class to parse JSON from a server in the iOS SDK? (similar to NSXML for XML and by extension RSS.)

iOS SDK 中是否有从服务器解析 JSON 的类?(类似于 XML 的 NSXML 和扩展 RSS。)

回答by Edwin

As of iOS5 JSON is been natively supported, no need for 3rd party frameworks. This is supported by the NSJSONSerialization Class!

从 iOS5 开始,JSON 已被原生支持,不需要 3rd 方框架。这由NSJSONSerialization 类支持!

回答by Jacob Relkin

Updated answer for iOS 5:

iOS 5 的更新答案:

JSON support is nownative to iOS with NSJSONSerialization, but in terms of performance, it pales in comparison to JSONKit, as John Englehart stated in the JSONKitREADME:

JSON 支持现在是 iOS 原生的NSJSONSerialization,但在性能方面,它与 相比相形见绌JSONKit,正如 John Englehart 在JSONKit自述文件中所述:

UPDATE: (2011/12/18) The benchmarks below were performed before Apples NSJSONSerialization was available (as of Mac OS X 10.7 and iOS 5). The obvious question is: Which is faster, NSJSONSerialization or JSONKit? According to this site, JSONKit is faster than NSJSONSerialization. Some quick "back of the envelope" calculations using the numbers reported, JSONKit appears to be approximately 25% to 40% faster than NSJSONSerialization, which is pretty significant.

更新:(2011/12/18) 下面的基准测试是在 Apples NSJSONSerialization 可用之前执行的(从 Mac OS X 10.7 和 iOS 5 开始)。最明显的问题是:这是更快,NSJSONSerialization或JSONKit?根据这个站点,JSONKit 比 NSJSONSerialization 快。使用报告的数字进行一些快速的“封底”计算,JSONKit 似乎比 NSJSONSerialization 快大约 25% 到 40%,这非常重要。

enter image description here

在此处输入图片说明

Here's a blog post which delves into more specific benchmarks: JSON Libraries for iOS Comparison

这是一篇深入研究更具体基准的博客文章:iOS 比较的 JSON 库

回答by hotpaw2

回答by nduplessis

NextiveJson is supposed to be quite a fast lib for iOS JSON NextiveJson

NextiveJson 应该是一个非常快的 iOS JSON 库 NextiveJson

回答by Oleh Kulykov

Regarding JSONKitbenchmarks, for the current moment and iOS version it's not so fast. After creating test application for testing speed NSJSONSerializationis faster but not so fast as custom implementation OKJSONParser

关于JSONKit基准测试,目前和 iOS 版本并没有那么快。创建测试应用程序后测试速度NSJSONSerialization更快但不如自定义实现OKJSONParser