0

Now I get a json file with data in this format:

[
  [
    "name1",
    "age1",
    "gender1",
    url1
  ],
  [
    "name2",
    "age2",
    "gender2",
    url2  
  ],
  ...    
]

Now I want to parse it and store them in my database by using Gson, but I don't know how to write the code to do it.

The list may contains about 200,000 small lists, so I don't know if it will take a lot of memory if I just use gson.fromJson() to get the whole json list. Is there a dynamic method to parse each small list in it?

4

1 回答 1

0
Gson 2.1 introduced a new TypeAdapter interface that permits mixed tree and streaming
serialization and deserialization.

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 has APIs to recursively skip an unwanted value; Gson calls this skipValue().

资料来源: JAVA - Jesse Wilson解析巨大(超大)JSON 文件的最佳方法

于 2013-08-19T17:53:16.823 回答