One way is to create POJO for your today
, week
, month
and result
. result
class will include list of the all other three that is today
, week
and month
.
Create one master POJO that contain your result
class object say MyJson
.Now you can directly parse this JSON into your class and from the getter method you have list of today
,week
and month
array.
To parse you JSON string into class object :
ObjectMapper mapper = new ObjectMapper();
MyJson resultObj = mapper.readValue(str, MyJson.class);
//get List of week
List<Week> week = resultObj.getResult().getWeek();
Your POJO classes look like :
MyJson.java
public class MyJson
{
private Result result;
//getter and setter method
}
Result.java
public class Result
{
private List<Today> today;
private List<Month> month;
private List<Week> week;
//getter and setter method
}
Today.java
public class Today
{
private String date;
//other parameters and it's getter and setter method.
}
Week.java
public class Week
{
private long ride_id;
private double trip_average_speed;
//other parameters and it's getter and setter method.
}
Month.java
public class Month
{
private String monthName;
//other parameters and it's getter and setter method.
}