0

我的 json 看起来像:

[
   {
      "schedule":[
         {
            "amount":19.98,
            "due_at":null,
            "identifier":"1549b45ff814e181dcbb983a02b35e9b3dd276fc-1",
            "paid_at":"2012-01-24",
            "status":"paid"
         }
      ]
   },
   {
      "schedule":[
         {
            "amount":24.68,
            "due_at":null,
            "identifier":"1549fdfdf814e181dcbb983a02b35e9b3dd276fc-1",
            "paid_at":"2012-08-14",
            "status":"paid"
         }
      ]
   }
]

我的日程表模型:

public class Schedule {
    public double amount;
    public String due_at;
    public String identifier;
    public String paid_at;
    public String status;
}

我的时间表模型:

public class Schedules extends HashMap<String, ArrayList<Schedule>>{
    private static final long serialVersionUID = 1L;
}

现在我使用:

ListSchedules objectMapper.readValue = (jp, new TypeReference <Schedules> () {});

但它不起作用,谁能告诉我要走的路

4

1 回答 1

1

修改如下

对于对象数组

Schedule[] objects = objectMapper.readValue(jp, Schedule[].class);

对于对象列表

    List<Schedule> objects = 
objectMapper.readValue(jp, new TypeReference<List<Schedule>>(){})

*假设jp是杰森文本

于 2013-01-28T11:24:11.270 回答