Android的gson流解析器或android.util.jsonreader? [英] Android gson streaming parser or android.util.jsonreader?

查看:95
本文介绍了Android的gson流解析器或android.util.jsonreader?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在Android应用中使用流式json解析器,我想知道是使用gson还是android.util.jsonreader库。假设许可和版本兼容性不是问题,我应该更喜欢这样做:




  • 我处理几MB数据。

  • JSON主要由压缩字符串组成,所以我并不真的需要一个Object到JSON映射。


解决方案

它并不重要: android.util.JsonReader com.google.gson.stream.JsonReader 是相同的代码。这两个类具有相同的API和相同的行为。



也就是说,有一些微小的差异:


  • Android的JsonReader仅适用于Android 3.0及更高版本。您可以在独立jar文件中使用Gson one任何版本的Android。

  • Gson的速度可能稍微快一点,因为它总是有最新的优化。运送Android设备的版本总是比最新和最好的版本略高。对于大多数应用程序,您不会注意到这种差异。


I'm looking to use a a streaming json parser in an Android app, and I am wondering whether to use gson or the android.util.jsonreader library. Supposing that licensing and version compatibility are not a problem, which should I prefer given that:

  • I process several MBs of data.
  • JSON mostly consists of compressed strings, so I don't really need an Object to JSON mapping.

解决方案

It doesn't much matter: android.util.JsonReader and com.google.gson.stream.JsonReader are the same code. The two classes have the same API and the same behavior.

That said, there are some tiny differences:

  • Android's JsonReader is only available in Android 3.0 and later. The Gson one is available in a standalone jar file that you can use on any version of Android.
  • Gson's may be a tiny bit faster simply because it always has the latest optimizations. The version on shipping Android devices is always slightly older than the latest and greatest. For most applications you won't notice this difference.

这篇关于Android的gson流解析器或android.util.jsonreader?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆