Objective-C 的 JSON 解析器比较(JSON 框架、YAJL、TouchJSON 等)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2256625/
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
Comparison of JSON Parser for Objective-C (JSON Framework, YAJL, TouchJSON, etc)
提问by tomute
As far as I know, there are three JSON Parsers for Objective-C, JSON Framework, YAJL, and Touch JSON. Then, These three would have their own characteristics.
For example:
YAJL can be used as a SAX style parser.
JSON Framework has relatively long history and is widely used.
Touch JSON parses NSData instead of NSString.
据我所知,Objective-C 有 3 个 JSON 解析器,JSON Framework,YAJL和Touch JSON。那么,这三者就会各有特点。
例如:
YAJL 可以用作 SAX 样式解析器。
JSON Framework 历史悠久,应用广泛。
Touch JSON 解析 NSData 而不是 NSString。
In addition, as far as I tested, the result of performance comparison is as follows:
[fast] YAJL > JSON Framework > Touch JSON[slow].
另外,据我测试,性能对比的结果如下:
【快】YAJL > JSON Framework > Touch JSON【慢】。
If you know pros and cons of these JSON parsers, could you tell me?
Lastly, if you know any other JSON Parser, please tell me.
如果你知道这些 JSON 解析器的优缺点,你能告诉我吗?
最后,如果您知道任何其他 JSON 解析器,请告诉我。
采纳答案by johne
If you're looking for speed, take a look at JSONKit. It is (usually) much faster than the already mentioned JSON libraries, often an order of magnitude faster. And because of it's "recently instantiated object cache", it will (again, usually) use less memory as well.
如果您正在寻找速度,请查看JSONKit。它(通常)比已经提到的 JSON 库快得多,通常快一个数量级。并且由于它是“最近实例化的对象缓存”,它也会(同样,通常)使用更少的内存。
回答by bontoJR
Considering a comparison that I did, the fastest library is JSONKit, followed by NSJSONSerialization (now public API) and NextiveJSON. SBJSON and TouchJSON are a little bit slower than the previous 3 libraries.
考虑到我所做的比较,最快的库是 JSONKit,其次是 NSJSONSerialization(现在是公共 API)和 NextiveJSON。SBJSON 和 TouchJSON 比前 3 个库慢一点。
The comparison has been done using an iPhone 4S with iOS 5.0.1.
比较是使用装有 iOS 5.0.1 的 iPhone 4S 完成的。
回答by Roman
There's also this parser:
还有这个解析器:
I don't remember how I stumbled upon this one, but it looked lightweight and simple, so I thought that it suits my needs. I event forked it in order to add initialization from NSData. As I needed to parse small responses, I didn't care about the performance. It would be interesting to know how it performs though.
我不记得我是如何偶然发现这个的,但它看起来轻巧简单,所以我认为它适合我的需求。我事件分叉它是为了从 NSData 添加初始化。因为我需要解析小的响应,所以我并不关心性能。不过,了解它的表现会很有趣。
回答by Arvind
I think JSONKit is faster than YAJL and YAJL is faster than Touch JSON and IOS5 class NSJSONSerialization class is much faster. NSJSONSerializationhave no need to use any third party APIs.
我认为 JSONKit 比 YAJL 快,YAJL 比 Touch JSON 快,IOS5 类 NSJSONSerialization 类要快得多。NSJSONSerialization不需要使用任何第三方 API。
回答by codeclash
Why not have a look at akosma's benchmarks on parsers where he compares different kinds of parsers. If one parser is missing, you might as well add it to the tests, since his code is open source.
为什么不看看 akosma 在解析器上的基准测试,他比较了不同类型的解析器。如果缺少一个解析器,您不妨将其添加到测试中,因为他的代码是开源的。
回答by Mahadevan Sreenivasan
If you are looking for a serializer from NSObject to JSON and vice versa, you might want to checkout OBJC JSONSerializer
如果您正在寻找从 NSObject 到 JSON 的序列化程序,反之亦然,您可能需要查看OBJC JSONSerializer

