2013-08-19 34 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