JAVA - 解析巨大(超大)JSON文件的最佳方法 [英] JAVA - Best approach to parse huge (extra large) JSON file

查看:4387
本文介绍了JAVA - 解析巨大(超大)JSON文件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析一些巨大的JSON文件(如 http:// eu.battle.net/auction-data/258993a3c6b974ef3e6f22ea6f822720/auctions.json )使用gson库( http://code.google.com/p/google-gson/ )。

I'm trying to parse some huge JSON file (like http://eu.battle.net/auction-data/258993a3c6b974ef3e6f22ea6f822720/auctions.json) using gson library (http://code.google.com/p/google-gson/) in JAVA.

我想知道解析这种大文件(大约80k行)的最佳方法,如果您可能知道可以帮助我处理这个问题的良好API 。

I would like to know what is the best approch to parse this kind of big file (about 80k lines) and if you may know good API that can help me processing this.

一些想法... ...

Some idea...


  1. 逐行阅读并摆脱JSON格式:但这是无稽之谈。 通过将这个文件分割成许多其他文件,
  2. 减少了JSON文件的数量:但是我没有找到任何好的Java API。

  3. 直接将此文件作为非Sql数据库使用,请保留该文件并将其用作我的数据库。

我真的很感激adices / help / messages / :-)
谢谢。

I would really appreciate adices/ help/ messages/ :-) Thanks.

推荐答案

您无需切换至Jackson。 Gson 2.1推出了新的 TypeAdapter 接口,它允许混合树和流式序列化和反序列化。

You don't need to switch to Jackson. Gson 2.1 introduced a new TypeAdapter interface that permits mixed tree and streaming serialization and deserialization.

该API高效灵活。有关组合树和绑定的示例,请参阅 Gson的流媒体文档。模式。这比混合流和树模式严格得多;与绑定你不浪费内存建立你的值的中间表示。

The API is efficient and flexible. See Gson's Streaming doc for an example of combining tree and binding modes. This is strictly better than mixed streaming and tree modes; with binding you don't waste memory building an intermediate representation of your values.

像杰克逊一样,Gson有API递归地跳过不需要的值; Gson将此称为 skipValue()

Like Jackson, Gson has APIs to recursively skip an unwanted value; Gson calls this skipValue().

这篇关于JAVA - 解析巨大(超大)JSON文件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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