替换标准 Android JSON 解析器以获得更好的性能?

发布于 2024-08-25 22:10:55 字数 169 浏览 7 评论 0原文

我知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

烟燃烟灭 2024-09-01 22:10:55

好吧,这里有一对链接将 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.

咿呀咿呀哟 2024-09-01 22:10:55

从 API 11 开始,Android 中有一个 流 json 解析器

Since API 11, there is a stream json parser in Android

So要识趣 2024-09-01 22:10:55

回答晚了,但可能仍然有帮助。我使用 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.

二智少女猫性小仙女 2024-09-01 22:10:55

只是对这些解析器的另一种看法。我正在浏览 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.

终难愈 2024-09-01 22:10:55

我使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文