i'm new to retrofit,below is the json
{
"response": "success",
"servicecode": "134",
"forecast": {
"month": {
"jan": [
{
"id": "1",
"price": "12",
"Product": "1086",
"Qty": "14",
"date": "2018-10-27 16:08:57"
},
{
"id": "2",
"price": "19",
"Product": "1746",
"Qty": "45",
"date": "2018-10-27 16:08:57"
}
],
"april": [
{
"id": "3",
"price": "89",
"Product": "1986",
"Qty": "15",
"date": "2018-10-27 16:08:57"
},
{
"id": "1",
"price": "12",
"Product": "1086",
"Qty": "145",
"date": "2018-10-27 16:08:57"
}
],
"jun": [
{
"id": "81",
"price": "132",
"Product": "17086",
"Qty": "1445",
"date": "2018-10-27 16:08:57"
},
{
"id": "11",
"price": "132",
"Product": "10786",
"Qty": "1445",
"date": "2018-10-27 16:08:57"
}
]
}
},
"message": "Competitor Sales."
}
here, those months(jan, april, jun) are dynamic(they may come or they won't) so how to parse this using retrofit. i have no idea how to create my model class. my issue some what looks like this,but in that there's no more details. tell me a better tutorial for this.
Model class below
class ForecastViewModel {
@SerializedName("forecast")
Forecast[] data;
public Forecast[] getData() { return data; }
private class Forecast {
@SerializedName("month")
MonthData[] month;
public MonthData[] getMonth() { return month; }
private class MonthData {
private Map<String, Pojo> forecastdata = new HashMap<>();
private class Pojo {
@SerializedName("id")
@Expose
private String pID;
@SerializedName("price")
@Expose
private String pPrice;
@SerializedName("Product")
@Expose
private String pProduct;
@SerializedName("Qty")
@Expose
private String pQty;
@SerializedName("date")
@Expose
private String pDate;
public String getpID() {
return pID;
}
public void setpID(String pID) {
this.pID = pID;
}
public String getpPrice() {
return pPrice;
}
public void setpPrice(String pPrice) {
this.pPrice = pPrice;
}
public String getpProduct() {
return pProduct;
}
public void setpProduct(String pProduct) {
this.pProduct = pProduct;
}
public String getpQty() {
return pQty;
}
public void setpQty(String pQty) {
this.pQty = pQty;
}
public String getpDate() {
return pDate;
}
public void setpDate(String pDate) {
this.pDate = pDate;
}
}
}
}
}
...!!