GSON解析动态JSON字段

我似乎无法弄清楚这一点。 我看了几个SOpost( 这里和这里 ),我的情况有点不同。

我不确定我是否必须注册一个新的TypeToken或什么。 但我的JSON对象如下所示:

{ "id": 6, "error": "0", "dates": { 34234 : "2011-01-01" // I want to parse the date into a string. 87474 : "2011-08-09" // The first values are all unique. . //this can be any number of entries. . . 74857 : "2011-09-22" } } 

我创建了两个像这样的对象:

 public class Response { public Integer id; public String error; public DateList dates; } 

单独的文件:

 public class DateList { public List<Map> dateString; } 

我不确定如何调整它以使其正确。 文档似乎没有帮助…我见过的其他示例是解析自定义对象,而不是字符串类型。

谢谢!

我试过这种forms:

杰森

 { "id": 6, "error": "0", "dates": { "34234" : "2011-01-01" "87474" : "2011-08-09" "74857" : "2011-09-22" } } 

和Response.java

 public class Response { public Integer id; public String error; public Map dates; } 

至少那似乎是开箱即用的。