I/m trying to put json to recyclerview using GSON but when i run it it gives me "Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $" error!
here is my json :
{"action":"true","error":"","data":[{"_id":"58ad8d8ca49d0e11e21c4504","store_name":"firstStore","store_view":0,"store_textposition":null},{"_id":"58ad9063cb35f5977b55dfd6","store_name":"firstStorestest","store_view":0,"store_textposition":null},{"_id":"58ad9088cb35f5977b55dfd7","store_name":"firstStorestest","store_view":0,"store_textposition":null}]}
and here is where i'm getting the error :
private void requestJsonObject(){
RequestQueue queue = Volley.newRequestQueue(getContext());
String url ="MYURL";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Response " + response);
GsonBuilder builder = new GsonBuilder();
Gson mGson = builder.create();
List<ItemObject> posts = new ArrayList<ItemObject>();
posts = Arrays.asList(mGson.fromJson(response, ItemObject[].class));
adapter = new RecyclerViewAdapter(getActivity(), posts);
recyclerView.setAdapter(adapter);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error " + error.getMessage());
}
});
queue.add(stringRequest);
}
and here is Itemobject.java
public class ItemObject {
@SerializedName("store_name")
private String store_name;
@SerializedName("store_textposition")
private String store_textposition;
@SerializedName("store_view")
private String store_view;
@SerializedName("_id")
private String _id;
public ItemObject(String store_name, String store_textposition, String store_view, String _id) {
this.store_name = store_name;
this.store_textposition = store_textposition;
this.store_view = store_view;
this._id = _id;
}
public String getStore_name() {
return store_name;
}
public String getStore_textposition() {
return store_textposition;
}
public String getStore_view() {
return store_view;
}
public String get_id(){
return _id;
}
What's wrong with it?