This is json array data / json object data from api getting error expected begin_array but was begin_object at line 3 and column 2 path$
This is json array data / json object data from api getting error expected begin_array but was begin_object at line 3 and column 2 path$
This is json array data / json object data from api getting error expected begin_array but was begin_object at line 3 and column 2 path$
This is json array data / json object data from api getting error expected begin_array but was begin_object at line 3 and column 2 path$
"offersdata": [
{
"offercode": "GRAB20",
"title": "Get Upto",
"description": "20% off on selected merchandise on purchase of INR 1000 or more"
},
{
"offercode": "JAN20",
"title": "Get Upto",
"description": "20% Off on all purchases in January"
},
{
"offercode": "BHHH",
"title": "DES",
"description": "FDSFS"
}
],
"message": "success"
}
@GET("user")
Call<List<limitedoffers>> getoffers();
package com.example.medico.models;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class limitedoffers {
@SerializedName("offersdata")
@Expose
private List<Offersdatum> offersdata = null;
@SerializedName("message")
@Expose
private String message;
public List<Offersdatum> getOffersdata() {
return offersdata;
}
public void setOffersdata(List<Offersdatum> offersdata) {
this.offersdata = offersdata;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.example.medico.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Offersdatum {
@SerializedName("offercode")
@Expose
private String offercode;
@SerializedName("title")
@Expose
private String title;
@SerializedName("description")
@Expose
private String description;
public String getOffercode() {
return offercode;
}
public void setOffercode(String offercode) {
this.offercode = offercode;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
I have read completely about Retrofit, Retrofit will work when the array is serialized perfectly.
"offersdata": [
{
"offercode": "GRAB20",
"title": "Get Upto",
"description": "20% off on selected merchandise on purchase of INR 1000 or more"
},
{
"offercode": "JAN20",
"title": "Get Upto",
"description": "20% Off on all purchases in January"
},
{
"offercode": "BHHH",
"title": "DES",
"description": "FDSFS"
}
],
"message": "success"
}
In the above Jsonarray offersdata has the ArrayList
In Interface class has to change code this
@GET("user")
Call<List<limitedoffers>> getoffers();
to this
@GET("user")
Call<limitedoffers> getoffers();
Because it doesn't contains ArrayList
For getting array from the Limitedoffers after the response Just use
response.body().getOffersdata();
to get the offersdata Arraylist