现在我得到一个包含这种格式数据的json文件:
[
[
"name1",
"age1",
"gender1",
url1
],
[
"name2",
"age2",
"gender2",
url2
],
...
]
现在我想解析它并使用Gson将它们存储在我的数据库中,但我不知道如何编写代码来执行它。
该列表可能包含大约200,000个小列表,所以如果我只使用gson.fromJson()来获取整个json列表,我不知道是否需要大量内存。是否有动态方法来解析其中的每个小列表?
答案 0 :(得分: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 - Best approach to parse huge (extra large) JSON file来自Jesse Wilson