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

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

问题描述

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

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.

有点想法...

  1. 逐行阅读并摆脱 JSON 格式:但这是无稽之谈.
  2. 通过将此文件拆分为许多其他文件来减少 JSON 文件:但我没有为此找到任何好的 Java API.
  3. 将此文件直接用作非Sql数据库,保留该文件并将其用作我的数据库.

我真的很感激阿迪斯/帮助/消息/:-)谢谢.

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.

像 Jackson 一样,Gson 有 API 可以递归地跳过不需要的值;Gson 将此称为 skipValue().

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

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

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