使用GSON进行Sickbeard API解析

时间:2014-04-29 10:45:28

标签: android json gson

在Android上使用Gson,如何设置我的Java类来解析JSON这样的Sickbeard API}:

{
"data": {
    "1": {
        "airdate": "2011-09-04", 
        "name": "Something Wicked This Fae Comes", 
        "quality": "HD TV", 
        "status": "Downloaded"
    }, 
    "2": {
        "airdate": "2011-09-11", 
        "name": "I Fought the Fae (And the Fae Won)", 
        "quality": "N/A", 
        "status": "Wanted"
    }, 
    "3": {
        "airdate": "2011-09-18", 
        "name": "Scream a Little Dream", 
        "quality": "N/A", 
        "status": "Unaired"
    }, 
    "4": {
        "airdate": "2011-09-25", 
        "name": "Episode 4", 
        "quality": "N/A", 
        "status": "Unaired"
    }, 
    "5": {
        "airdate": "", 
        "name": "Episode 5", 
        "quality": "N/A", 
        "status": "Skipped"
    }
}, 
"message": "", 
"result": "success"
}

这些“1”,“2”等可以是从0到任何数字的数字(甚至可能是“特价”)。

1 个答案:

答案 0 :(得分:1)

您的课程应如下所示

课程回复

@Expose @SerializedName("data")
private HashMap<Integer, DataObject> dataList;

@Expose @SerializedName("message")
private String message;

@Expose @SerializedName("result")
private String result;

类DataObject

@Expose @SerializedName("airdate")
private String airdate;

@Expose @SerializedName("name")
private String name;

... //other objects

getter和setter等等,现在你应该能够解析它了。但如果你有可能改变api,我建议你把数据列表更改为真正的json对象列表!!