2013-08-19 36 views
0

现在,我得到这个格式数据的JSON文件:如何使用Gson解析json列表中的数据?

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

现在我想对它进行解析,并通过使用GSON他们在我的数据库存储,但我不知道怎么写代码来执行它。

该列表可能包含大约200,000个小列表,因此我不知道如果使用gson.fromJson()获取整个json列表,它是否会占用大量内存。是否有动态的方法来解析每个小列表?

回答

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