替换标准 Android JSON 解析器以获得更好的性能?
我知道 Android 有一个内置的 JSON 解析器,但我想知道是否值得使用提供更好性能的东西(比如 Jackson - 请参阅 http://jackson.codehaus.org/)?有人试过吗?
I know that Android has a JSON parser baked in but I was wondering if it was worth using something that offered better performance (like Jackson - see http://jackson.codehaus.org/) ? Anybody tried that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,这里有一对链接将 Jackson JSON 性能与现有 JSON、SAX 和 Protocol Buffers 进行比较。据作者称,Jackson 比 SAX 或内置 JSON 更快,并且与 Protocol Buffers 相当。最后一部分听起来有点可疑,但无论如何,Jackson 确实可以在 Android 上运行,并且可能值得进行一些实验。
不过我还没有检查过 JAR 的大小。如果它很大,除非您非常渴望额外的 JSON 性能,否则可能不值得占用空间。
Well, here are a couple of links comparing Jackson JSON performance with existing JSON, SAX, and Protocol Buffers. According to the author, Jackson is faster than SAX or the built-in JSON and about on par with Protocol Buffers. That last part sounds a little suspicious, but, regardless, it certainly appears Jackson works on Android and may be worth some experimentation.
I haven't checked the JAR size, though. If it's huge, unless you were dying for extra JSON performance, it might not be worth the space hit.
从 API 11 开始,Android 中有一个 流 json 解析器
Since API 11, there is a stream json parser in Android
回答晚了,但可能仍然有帮助。我使用 Jackson 解析来自 Twitter 的 JSON 并将
Maps
保存到数据库。杰克逊的数据映射非常棒。能够将 JSON 直接映射到对象真是太棒了,并且让一切变得更加清晰。即使您只是解析简单的回复,数据映射也可能会帮助您使代码更干净(并且更高效)。对我来说,这是天赐之物,我不必为每种类型的 Twitter api 函数编写解析逻辑。
Late answer but it might still help. I'm using Jackson for parsing JSON from Twitter as well as persisting
Maps
to the database. The data mapping in Jackson is just wonderful. Being able to map JSON directly to an object is awesome and makes everything alot cleaner.Even if you are only parsing simple replies data mapping might help you make your code cleaner (and more efficient). For me it's godsend that I don't have to write parsing logic for every type of Twitter api function.
只是对这些解析器的另一种看法。我正在浏览 2009 年的 Google IO,其中关于应用程序开发人员如何有效使用电池的讨论非常精彩。
以下是该演讲的链接: 链接
现在,根据演讲,Android 的内置牧师是基于树的,这些是就电池寿命而言,应该是低效的。有没有人真正研究过这个问题。
通过阅读这个讨论,杰克逊解析器似乎在所有方面都是赢家。它几乎同样快,甚至比内置的快,而且它基于事件/流,而不是基于树,这在电池使用方面更好。
只是我想就此分享并获得一些意见。
Just one more perspective on these parsers. I was looking through the Google IO for 2009 and there is really nice talk about efficient use of battery for app developers.
Here is the link to that talk : link
Now as per the talk inbuilt parson for android is Tree Based and these are supposed to be inefficient when it comes to battery life. Has anyone really looked into this.
Reading through this discussion it seem Jackson parser seems to be a winner in everything. Its almost equally fast if not more than inbuilt one and also its Event/Stream based as opposed to tree based which is better in terms of battery usage.
Just a though I wanted to share and get some opinions on this.
我使用 jackson json 来实现我的 android 应用程序,该应用程序通过 json-rpc 与服务器进行通信。我想用它来序列化/反序列化 json-rpc 请求和响应以及对象来传输数据。
我使用 2.0 版本的 Jackson-json。我在构建路径中放入了两个 jar:jackson-databind-2.0.0.jar、jackson-core-2.0.0.jar 和 jackson-annotations-2.0.0.jar。
旁注:是否有适用于 android.json 的 json-rpc 实现?单独的 json-rpc 和 http 流量会很好。我用谷歌搜索了很多,但没有找到好的 json-rpc 生成器、json 序列化器/反序列化器,对于传输,我将使用 android-query。
I use jackson json to implement my android application which communicates with server via json-rpc. I wold like to use it to serialize/deserialize json-rpc requests and responses and objects to transfer the data.
I use 2.0 version of Jackson-json. I have put in my build path two jars: jackson-databind-2.0.0.jar, jackson-core-2.0.0.jar and jackson-annotations-2.0.0.jar.
On the side note: Are there any json-rpc implementation for the android. separate json-rpc and http traffic would be good. I have googled a lot, bu have not found good json-rpc generator, json serializer / deserializer and for the transport I will go with android-query.