Gson,使用改进解析数组的对象

时间:2015-11-09 12:35:31

标签: android json gson retrofit

我有这个服务器响应:

{ "result" : true , "content" : {
    "files" : [],
    "filesNames" : [],
    "folders" : []
    }
}

如何创建一个gson对象以使改造适应该响应?因为这似乎不起作用(我只需要文件和文件夹):

public class GetUserFilesAnswer {

    public boolean result;
    public List<Integer> files;
    public List<String> folders;


}

client.getUserFiles(email, token, path, new Callback<GetUserFilesAnswer>() {
        @Override
        public void success(GetUserFilesAnswer getUserFilesAnswer, Response response) {
        }

        @Override
        public void failure(RetrofitError error) {

        }
    });

1 个答案:

答案 0 :(得分:1)

试试这个型号:

public class GetUserFilesAnswer {

    public static class Content {
       public List<Integer> files;
       public List<String> folders;
    }

    public boolean result;
    public Content content;

}