com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was...












0














I have an json output like below.



[{"FoodName":"fish","image":"http://ckckc.com/images/60.png","loginname":"sss","time":"1525706184851","userid":"1","profile":"http://ckckc.com/profile/0.png","cuisine":"pomfret fry","wherefrom":"fish shop","locality":"xxx block ","random":"0869155d","id":"61","city":"","like":"0","follow":"profile"}]


I am getting this using StringRequest in Volley to get the response. Am using Gson library to parse and it was working fine. But suddenly i am getting the below error.



com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]


Am not sure whats went wrong. Gson code used to parseis mentioned below.



Gson gson = new Gson();
ArrayList<descusers> dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());


s is my response. I have cross checked all the values in the descusers and variables are matching. Please help.



Cleaned and Rebuild the project but no use. In error it mentioned as path.$[0] and i am not sure which objects it points.



My POJO class:



 class descusers extends ArrayList<Parcelable> implements Parcelable {
String descCrip;
String loginname;
String image;
long Ptime;
String profile;
String Image;
String cuisine;
String where;
String locality;
int id;
String random;
String comment;
String reply;
double latitude,longitude;
int like;
int likecount;
int sharecount;
int commentid;
int commentcount;
int replycount;
int commentrepliesid;
int userid;
String city;
String username;
int present;
String followcheckinlists;

long timeofaction;
int idofpost;
String actionuserprofile;
int actionuserid;
String actionusername;
String usernameofpost;
String action;
String postimage;
String follow;
String FoodName;
String wherefrom;
long time;
int useridofpost;

public long getTime() {
return time;
}

public void setTime(long time) {
this.time = time;
}

public void setReplycount(int replycount) {
this.replycount = replycount;
}

public String getFoodName() {
return FoodName;
}

public void setFoodName(String foodName) {
FoodName = foodName;
}

protected descusers(Parcel in) {
descCrip = in.readString();
loginname = in.readString();
image = in.readString();
Ptime = in.readLong();
profile = in.readString();
Image = in.readString();
cuisine = in.readString();
where = in.readString();
locality = in.readString();
id = in.readInt();
random = in.readString();
comment = in.readString();
reply = in.readString();
city = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
like = in.readInt();
likecount = in.readInt();
sharecount = in.readInt();
commentid = in.readInt();
commentcount = in.readInt();
replycount = in.readInt();
commentrepliesid = in.readInt();
userid = in.readInt();
username = in.readString();
present = in.readInt();
followcheckinlists = in.readString();
timeofaction = in.readLong();
idofpost = in.readInt();
actionuserprofile = in.readString();
actionuserid = in.readInt();
actionusername = in.readString();
usernameofpost = in.readString();
action = in.readString();
postimage = in.readString();
follow = in.readString();
FoodName = in.readString();
wherefrom = in.readString();
time = in.readLong();
useridofpost = in.readInt();


}

public static final Creator<descusers> CREATOR = new Creator<descusers>() {
@Override
public descusers createFromParcel(Parcel in) {
return new descusers(in);
}

@Override
public descusers newArray(int size) {
return new descusers[size];
}
};

public int getUserid() {
return userid;
}

public void setUserid(int userid) {
this.userid = userid;
}

public void setPtime(long ptime) {
Ptime = ptime;
}



public void setProfile(String profile) {
this.profile = profile;
}


public String getProfile() {
return profile;
}




public int getCommentrepliesid() {
return commentrepliesid;
}

public descusers() {

}

public String getRandom() {
return random;
}

public void setRandom(String random) {
this.random = random;
}

public String getLoginname() {

return loginname;
}

public String getComment() {
return comment;
}


public String getDescCrip() {
return descCrip;
}

public void setDescCrip(String descCrip) {
this.descCrip = descCrip;
}

public int getCommentid() {
return commentid;
}

public void setCommentcount(int commentcount) {
this.commentcount = commentcount;
}

public int getCommentcount() {
return commentcount;
}

public void setSharecount(int sharecount) {
this.sharecount = sharecount;
}

public void setCity(String city) {
this.city = city;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public String getCity() {
return city;
}

public double getLatitude() {
return latitude;
}

public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {

this.longitude = longitude;
}

public String getReply() {
return reply;
}

public String getName(){
return loginname;
}

public String getCuisine() {
return cuisine;
}

public String getWhere() {
return where;
}

public void setLoginname(String loginname) {
this.loginname = loginname;
}

public String getLocality() {
return locality;
}

public String getimage() {
return image;
}

public void setimage(String image) {
this.image = image;
}

public void setId(int id) {
this.id = id;
}

public int getLikecount() {
return likecount;
}

public int getId() {

return id;

}

public void setLikecount(int likecount) {
this.likecount = likecount;
}

public void setLike(int like) {
this.like = like;

}

public void setCuisine(String cuisine) {
this.cuisine = cuisine;
}

public void setWhere(String where) {
this.where = where;
}

public void setLocality(String locality) {
this.locality = locality;
}

public int getLike() { return like; }

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}





public long getPtime() {
return Ptime;
}

@Override
public int describeContents() {
return 0;
}

public int getPresent() {
return present;
}

public void setPresent(int present) {
this.present = present;
}

public String getFollowcheckinlists() {
return followcheckinlists;
}

public long getTimeofaction() {
return timeofaction;
}

public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public void setTimeofaction(long timeofaction) {
this.timeofaction = timeofaction;
}

public int getIdofpost() {
return idofpost;
}

public void setIdofpost(int idofpost) {
this.idofpost = idofpost;
}

public String getActionuserprofile() {
return actionuserprofile;
}

public void setActionuserprofile(String actionuserprofile) {
this.actionuserprofile = actionuserprofile;
}

public int getActionuserid() {
return actionuserid;
}

public void setActionuserid(int actionuserid) {
this.actionuserid = actionuserid;
}

public String getActionusername() {
return actionusername;
}

public void setActionusername(String actionusername) {
this.actionusername = actionusername;
}

public String getUsernameofpost() {
return usernameofpost;
}

public void setUsernameofpost(String usernameofpost) {
this.usernameofpost = usernameofpost;
}

public String getPostimage() {
return postimage;
}

public void setPostimage(String postimage) {
this.postimage = postimage;
}

public void setFollowcheckinlists(String followcheckinlists) {
this.followcheckinlists = followcheckinlists;
}

public String getFollow() {
return follow;
}

public void setFollow(String follow) {
this.follow = follow;
}



@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(descCrip);
dest.writeString(loginname);
dest.writeString(image);
dest.writeLong(Ptime);
dest.writeString(profile);
dest.writeString(Image);
dest.writeString(cuisine);
dest.writeString(where);
dest.writeString(locality);
dest.writeInt(id);
dest.writeString(random);

dest.writeString(comment);
dest.writeString(reply);
dest.writeString(city);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeInt(like);

dest.writeInt(likecount);
dest.writeInt(sharecount);
dest.writeInt(commentid);
dest.writeInt(commentcount);
dest.writeInt(replycount);
dest.writeInt(commentrepliesid);
dest.writeInt(userid);
dest.writeString(username);

dest.writeInt(present);
dest.writeString(followcheckinlists);

dest.writeLong(timeofaction);
dest.writeInt(idofpost);
dest.writeString(actionuserprofile);
dest.writeInt(actionuserid);
dest.writeString(actionusername);
dest.writeString(usernameofpost);
dest.writeString(action);
dest.writeString(postimage);
dest.writeString(follow);
dest.writeString(FoodName);
dest.writeString(wherefrom);
dest.writeLong(time);
dest.writeInt(useridofpost);

}

}


Method used for getting response from server.



    private void listdisp(String query, String locationname, String uname, int id) {
m.mShimmerViewContainer.startShimmer();
m.mShimmerViewContainer.setVisibility(View.VISIBLE);

StringRequest stringRequest = new StringRequest(Request.Method.POST, BuildConfig.LD,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
if (s != null && !s.isEmpty() && !s.equals("no results"))
{
Gson gson = new Gson();
m.dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());
FragmentActivity c = getActivity();
m.fpa = new followpostAdapter(c, m.dusers,m.user,m.s);
m.lists.setAdapter(m.fpa);
m.lists.setVisibility(View.VISIBLE);
// m.lists.setTextFilterEnabled(false);
// m.lists.setEmptyView(m.emptyElement);
m.mShimmerViewContainer.stopShimmer();
m.mShimmerViewContainer.setVisibility(View.GONE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {

@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new Hashtable<String, String>();
params.put("deskey", query);
params.put("uname",uname);
params.put("locationame",locationname);
params.put("userid",String.valueOf(id));
return params;
}
};
int socketTimeout = 60000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);

}









share|improve this question
























  • The error states that while you were expecting the Json to start with an array, it started with an object. If double check the received Json.
    – Fred
    Nov 20 at 8:12










  • It seems 'descusers' object is the problem.
    – H. Ekici
    Nov 20 at 8:14










  • Please post your pojo as well
    – Akshay Paliwal
    Nov 20 at 8:17










  • Posted POJO Classes and Volleymethod.
    – user2269164
    Nov 20 at 8:25
















0














I have an json output like below.



[{"FoodName":"fish","image":"http://ckckc.com/images/60.png","loginname":"sss","time":"1525706184851","userid":"1","profile":"http://ckckc.com/profile/0.png","cuisine":"pomfret fry","wherefrom":"fish shop","locality":"xxx block ","random":"0869155d","id":"61","city":"","like":"0","follow":"profile"}]


I am getting this using StringRequest in Volley to get the response. Am using Gson library to parse and it was working fine. But suddenly i am getting the below error.



com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]


Am not sure whats went wrong. Gson code used to parseis mentioned below.



Gson gson = new Gson();
ArrayList<descusers> dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());


s is my response. I have cross checked all the values in the descusers and variables are matching. Please help.



Cleaned and Rebuild the project but no use. In error it mentioned as path.$[0] and i am not sure which objects it points.



My POJO class:



 class descusers extends ArrayList<Parcelable> implements Parcelable {
String descCrip;
String loginname;
String image;
long Ptime;
String profile;
String Image;
String cuisine;
String where;
String locality;
int id;
String random;
String comment;
String reply;
double latitude,longitude;
int like;
int likecount;
int sharecount;
int commentid;
int commentcount;
int replycount;
int commentrepliesid;
int userid;
String city;
String username;
int present;
String followcheckinlists;

long timeofaction;
int idofpost;
String actionuserprofile;
int actionuserid;
String actionusername;
String usernameofpost;
String action;
String postimage;
String follow;
String FoodName;
String wherefrom;
long time;
int useridofpost;

public long getTime() {
return time;
}

public void setTime(long time) {
this.time = time;
}

public void setReplycount(int replycount) {
this.replycount = replycount;
}

public String getFoodName() {
return FoodName;
}

public void setFoodName(String foodName) {
FoodName = foodName;
}

protected descusers(Parcel in) {
descCrip = in.readString();
loginname = in.readString();
image = in.readString();
Ptime = in.readLong();
profile = in.readString();
Image = in.readString();
cuisine = in.readString();
where = in.readString();
locality = in.readString();
id = in.readInt();
random = in.readString();
comment = in.readString();
reply = in.readString();
city = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
like = in.readInt();
likecount = in.readInt();
sharecount = in.readInt();
commentid = in.readInt();
commentcount = in.readInt();
replycount = in.readInt();
commentrepliesid = in.readInt();
userid = in.readInt();
username = in.readString();
present = in.readInt();
followcheckinlists = in.readString();
timeofaction = in.readLong();
idofpost = in.readInt();
actionuserprofile = in.readString();
actionuserid = in.readInt();
actionusername = in.readString();
usernameofpost = in.readString();
action = in.readString();
postimage = in.readString();
follow = in.readString();
FoodName = in.readString();
wherefrom = in.readString();
time = in.readLong();
useridofpost = in.readInt();


}

public static final Creator<descusers> CREATOR = new Creator<descusers>() {
@Override
public descusers createFromParcel(Parcel in) {
return new descusers(in);
}

@Override
public descusers newArray(int size) {
return new descusers[size];
}
};

public int getUserid() {
return userid;
}

public void setUserid(int userid) {
this.userid = userid;
}

public void setPtime(long ptime) {
Ptime = ptime;
}



public void setProfile(String profile) {
this.profile = profile;
}


public String getProfile() {
return profile;
}




public int getCommentrepliesid() {
return commentrepliesid;
}

public descusers() {

}

public String getRandom() {
return random;
}

public void setRandom(String random) {
this.random = random;
}

public String getLoginname() {

return loginname;
}

public String getComment() {
return comment;
}


public String getDescCrip() {
return descCrip;
}

public void setDescCrip(String descCrip) {
this.descCrip = descCrip;
}

public int getCommentid() {
return commentid;
}

public void setCommentcount(int commentcount) {
this.commentcount = commentcount;
}

public int getCommentcount() {
return commentcount;
}

public void setSharecount(int sharecount) {
this.sharecount = sharecount;
}

public void setCity(String city) {
this.city = city;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public String getCity() {
return city;
}

public double getLatitude() {
return latitude;
}

public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {

this.longitude = longitude;
}

public String getReply() {
return reply;
}

public String getName(){
return loginname;
}

public String getCuisine() {
return cuisine;
}

public String getWhere() {
return where;
}

public void setLoginname(String loginname) {
this.loginname = loginname;
}

public String getLocality() {
return locality;
}

public String getimage() {
return image;
}

public void setimage(String image) {
this.image = image;
}

public void setId(int id) {
this.id = id;
}

public int getLikecount() {
return likecount;
}

public int getId() {

return id;

}

public void setLikecount(int likecount) {
this.likecount = likecount;
}

public void setLike(int like) {
this.like = like;

}

public void setCuisine(String cuisine) {
this.cuisine = cuisine;
}

public void setWhere(String where) {
this.where = where;
}

public void setLocality(String locality) {
this.locality = locality;
}

public int getLike() { return like; }

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}





public long getPtime() {
return Ptime;
}

@Override
public int describeContents() {
return 0;
}

public int getPresent() {
return present;
}

public void setPresent(int present) {
this.present = present;
}

public String getFollowcheckinlists() {
return followcheckinlists;
}

public long getTimeofaction() {
return timeofaction;
}

public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public void setTimeofaction(long timeofaction) {
this.timeofaction = timeofaction;
}

public int getIdofpost() {
return idofpost;
}

public void setIdofpost(int idofpost) {
this.idofpost = idofpost;
}

public String getActionuserprofile() {
return actionuserprofile;
}

public void setActionuserprofile(String actionuserprofile) {
this.actionuserprofile = actionuserprofile;
}

public int getActionuserid() {
return actionuserid;
}

public void setActionuserid(int actionuserid) {
this.actionuserid = actionuserid;
}

public String getActionusername() {
return actionusername;
}

public void setActionusername(String actionusername) {
this.actionusername = actionusername;
}

public String getUsernameofpost() {
return usernameofpost;
}

public void setUsernameofpost(String usernameofpost) {
this.usernameofpost = usernameofpost;
}

public String getPostimage() {
return postimage;
}

public void setPostimage(String postimage) {
this.postimage = postimage;
}

public void setFollowcheckinlists(String followcheckinlists) {
this.followcheckinlists = followcheckinlists;
}

public String getFollow() {
return follow;
}

public void setFollow(String follow) {
this.follow = follow;
}



@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(descCrip);
dest.writeString(loginname);
dest.writeString(image);
dest.writeLong(Ptime);
dest.writeString(profile);
dest.writeString(Image);
dest.writeString(cuisine);
dest.writeString(where);
dest.writeString(locality);
dest.writeInt(id);
dest.writeString(random);

dest.writeString(comment);
dest.writeString(reply);
dest.writeString(city);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeInt(like);

dest.writeInt(likecount);
dest.writeInt(sharecount);
dest.writeInt(commentid);
dest.writeInt(commentcount);
dest.writeInt(replycount);
dest.writeInt(commentrepliesid);
dest.writeInt(userid);
dest.writeString(username);

dest.writeInt(present);
dest.writeString(followcheckinlists);

dest.writeLong(timeofaction);
dest.writeInt(idofpost);
dest.writeString(actionuserprofile);
dest.writeInt(actionuserid);
dest.writeString(actionusername);
dest.writeString(usernameofpost);
dest.writeString(action);
dest.writeString(postimage);
dest.writeString(follow);
dest.writeString(FoodName);
dest.writeString(wherefrom);
dest.writeLong(time);
dest.writeInt(useridofpost);

}

}


Method used for getting response from server.



    private void listdisp(String query, String locationname, String uname, int id) {
m.mShimmerViewContainer.startShimmer();
m.mShimmerViewContainer.setVisibility(View.VISIBLE);

StringRequest stringRequest = new StringRequest(Request.Method.POST, BuildConfig.LD,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
if (s != null && !s.isEmpty() && !s.equals("no results"))
{
Gson gson = new Gson();
m.dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());
FragmentActivity c = getActivity();
m.fpa = new followpostAdapter(c, m.dusers,m.user,m.s);
m.lists.setAdapter(m.fpa);
m.lists.setVisibility(View.VISIBLE);
// m.lists.setTextFilterEnabled(false);
// m.lists.setEmptyView(m.emptyElement);
m.mShimmerViewContainer.stopShimmer();
m.mShimmerViewContainer.setVisibility(View.GONE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {

@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new Hashtable<String, String>();
params.put("deskey", query);
params.put("uname",uname);
params.put("locationame",locationname);
params.put("userid",String.valueOf(id));
return params;
}
};
int socketTimeout = 60000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);

}









share|improve this question
























  • The error states that while you were expecting the Json to start with an array, it started with an object. If double check the received Json.
    – Fred
    Nov 20 at 8:12










  • It seems 'descusers' object is the problem.
    – H. Ekici
    Nov 20 at 8:14










  • Please post your pojo as well
    – Akshay Paliwal
    Nov 20 at 8:17










  • Posted POJO Classes and Volleymethod.
    – user2269164
    Nov 20 at 8:25














0












0








0







I have an json output like below.



[{"FoodName":"fish","image":"http://ckckc.com/images/60.png","loginname":"sss","time":"1525706184851","userid":"1","profile":"http://ckckc.com/profile/0.png","cuisine":"pomfret fry","wherefrom":"fish shop","locality":"xxx block ","random":"0869155d","id":"61","city":"","like":"0","follow":"profile"}]


I am getting this using StringRequest in Volley to get the response. Am using Gson library to parse and it was working fine. But suddenly i am getting the below error.



com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]


Am not sure whats went wrong. Gson code used to parseis mentioned below.



Gson gson = new Gson();
ArrayList<descusers> dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());


s is my response. I have cross checked all the values in the descusers and variables are matching. Please help.



Cleaned and Rebuild the project but no use. In error it mentioned as path.$[0] and i am not sure which objects it points.



My POJO class:



 class descusers extends ArrayList<Parcelable> implements Parcelable {
String descCrip;
String loginname;
String image;
long Ptime;
String profile;
String Image;
String cuisine;
String where;
String locality;
int id;
String random;
String comment;
String reply;
double latitude,longitude;
int like;
int likecount;
int sharecount;
int commentid;
int commentcount;
int replycount;
int commentrepliesid;
int userid;
String city;
String username;
int present;
String followcheckinlists;

long timeofaction;
int idofpost;
String actionuserprofile;
int actionuserid;
String actionusername;
String usernameofpost;
String action;
String postimage;
String follow;
String FoodName;
String wherefrom;
long time;
int useridofpost;

public long getTime() {
return time;
}

public void setTime(long time) {
this.time = time;
}

public void setReplycount(int replycount) {
this.replycount = replycount;
}

public String getFoodName() {
return FoodName;
}

public void setFoodName(String foodName) {
FoodName = foodName;
}

protected descusers(Parcel in) {
descCrip = in.readString();
loginname = in.readString();
image = in.readString();
Ptime = in.readLong();
profile = in.readString();
Image = in.readString();
cuisine = in.readString();
where = in.readString();
locality = in.readString();
id = in.readInt();
random = in.readString();
comment = in.readString();
reply = in.readString();
city = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
like = in.readInt();
likecount = in.readInt();
sharecount = in.readInt();
commentid = in.readInt();
commentcount = in.readInt();
replycount = in.readInt();
commentrepliesid = in.readInt();
userid = in.readInt();
username = in.readString();
present = in.readInt();
followcheckinlists = in.readString();
timeofaction = in.readLong();
idofpost = in.readInt();
actionuserprofile = in.readString();
actionuserid = in.readInt();
actionusername = in.readString();
usernameofpost = in.readString();
action = in.readString();
postimage = in.readString();
follow = in.readString();
FoodName = in.readString();
wherefrom = in.readString();
time = in.readLong();
useridofpost = in.readInt();


}

public static final Creator<descusers> CREATOR = new Creator<descusers>() {
@Override
public descusers createFromParcel(Parcel in) {
return new descusers(in);
}

@Override
public descusers newArray(int size) {
return new descusers[size];
}
};

public int getUserid() {
return userid;
}

public void setUserid(int userid) {
this.userid = userid;
}

public void setPtime(long ptime) {
Ptime = ptime;
}



public void setProfile(String profile) {
this.profile = profile;
}


public String getProfile() {
return profile;
}




public int getCommentrepliesid() {
return commentrepliesid;
}

public descusers() {

}

public String getRandom() {
return random;
}

public void setRandom(String random) {
this.random = random;
}

public String getLoginname() {

return loginname;
}

public String getComment() {
return comment;
}


public String getDescCrip() {
return descCrip;
}

public void setDescCrip(String descCrip) {
this.descCrip = descCrip;
}

public int getCommentid() {
return commentid;
}

public void setCommentcount(int commentcount) {
this.commentcount = commentcount;
}

public int getCommentcount() {
return commentcount;
}

public void setSharecount(int sharecount) {
this.sharecount = sharecount;
}

public void setCity(String city) {
this.city = city;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public String getCity() {
return city;
}

public double getLatitude() {
return latitude;
}

public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {

this.longitude = longitude;
}

public String getReply() {
return reply;
}

public String getName(){
return loginname;
}

public String getCuisine() {
return cuisine;
}

public String getWhere() {
return where;
}

public void setLoginname(String loginname) {
this.loginname = loginname;
}

public String getLocality() {
return locality;
}

public String getimage() {
return image;
}

public void setimage(String image) {
this.image = image;
}

public void setId(int id) {
this.id = id;
}

public int getLikecount() {
return likecount;
}

public int getId() {

return id;

}

public void setLikecount(int likecount) {
this.likecount = likecount;
}

public void setLike(int like) {
this.like = like;

}

public void setCuisine(String cuisine) {
this.cuisine = cuisine;
}

public void setWhere(String where) {
this.where = where;
}

public void setLocality(String locality) {
this.locality = locality;
}

public int getLike() { return like; }

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}





public long getPtime() {
return Ptime;
}

@Override
public int describeContents() {
return 0;
}

public int getPresent() {
return present;
}

public void setPresent(int present) {
this.present = present;
}

public String getFollowcheckinlists() {
return followcheckinlists;
}

public long getTimeofaction() {
return timeofaction;
}

public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public void setTimeofaction(long timeofaction) {
this.timeofaction = timeofaction;
}

public int getIdofpost() {
return idofpost;
}

public void setIdofpost(int idofpost) {
this.idofpost = idofpost;
}

public String getActionuserprofile() {
return actionuserprofile;
}

public void setActionuserprofile(String actionuserprofile) {
this.actionuserprofile = actionuserprofile;
}

public int getActionuserid() {
return actionuserid;
}

public void setActionuserid(int actionuserid) {
this.actionuserid = actionuserid;
}

public String getActionusername() {
return actionusername;
}

public void setActionusername(String actionusername) {
this.actionusername = actionusername;
}

public String getUsernameofpost() {
return usernameofpost;
}

public void setUsernameofpost(String usernameofpost) {
this.usernameofpost = usernameofpost;
}

public String getPostimage() {
return postimage;
}

public void setPostimage(String postimage) {
this.postimage = postimage;
}

public void setFollowcheckinlists(String followcheckinlists) {
this.followcheckinlists = followcheckinlists;
}

public String getFollow() {
return follow;
}

public void setFollow(String follow) {
this.follow = follow;
}



@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(descCrip);
dest.writeString(loginname);
dest.writeString(image);
dest.writeLong(Ptime);
dest.writeString(profile);
dest.writeString(Image);
dest.writeString(cuisine);
dest.writeString(where);
dest.writeString(locality);
dest.writeInt(id);
dest.writeString(random);

dest.writeString(comment);
dest.writeString(reply);
dest.writeString(city);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeInt(like);

dest.writeInt(likecount);
dest.writeInt(sharecount);
dest.writeInt(commentid);
dest.writeInt(commentcount);
dest.writeInt(replycount);
dest.writeInt(commentrepliesid);
dest.writeInt(userid);
dest.writeString(username);

dest.writeInt(present);
dest.writeString(followcheckinlists);

dest.writeLong(timeofaction);
dest.writeInt(idofpost);
dest.writeString(actionuserprofile);
dest.writeInt(actionuserid);
dest.writeString(actionusername);
dest.writeString(usernameofpost);
dest.writeString(action);
dest.writeString(postimage);
dest.writeString(follow);
dest.writeString(FoodName);
dest.writeString(wherefrom);
dest.writeLong(time);
dest.writeInt(useridofpost);

}

}


Method used for getting response from server.



    private void listdisp(String query, String locationname, String uname, int id) {
m.mShimmerViewContainer.startShimmer();
m.mShimmerViewContainer.setVisibility(View.VISIBLE);

StringRequest stringRequest = new StringRequest(Request.Method.POST, BuildConfig.LD,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
if (s != null && !s.isEmpty() && !s.equals("no results"))
{
Gson gson = new Gson();
m.dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());
FragmentActivity c = getActivity();
m.fpa = new followpostAdapter(c, m.dusers,m.user,m.s);
m.lists.setAdapter(m.fpa);
m.lists.setVisibility(View.VISIBLE);
// m.lists.setTextFilterEnabled(false);
// m.lists.setEmptyView(m.emptyElement);
m.mShimmerViewContainer.stopShimmer();
m.mShimmerViewContainer.setVisibility(View.GONE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {

@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new Hashtable<String, String>();
params.put("deskey", query);
params.put("uname",uname);
params.put("locationame",locationname);
params.put("userid",String.valueOf(id));
return params;
}
};
int socketTimeout = 60000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);

}









share|improve this question















I have an json output like below.



[{"FoodName":"fish","image":"http://ckckc.com/images/60.png","loginname":"sss","time":"1525706184851","userid":"1","profile":"http://ckckc.com/profile/0.png","cuisine":"pomfret fry","wherefrom":"fish shop","locality":"xxx block ","random":"0869155d","id":"61","city":"","like":"0","follow":"profile"}]


I am getting this using StringRequest in Volley to get the response. Am using Gson library to parse and it was working fine. But suddenly i am getting the below error.



com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]


Am not sure whats went wrong. Gson code used to parseis mentioned below.



Gson gson = new Gson();
ArrayList<descusers> dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());


s is my response. I have cross checked all the values in the descusers and variables are matching. Please help.



Cleaned and Rebuild the project but no use. In error it mentioned as path.$[0] and i am not sure which objects it points.



My POJO class:



 class descusers extends ArrayList<Parcelable> implements Parcelable {
String descCrip;
String loginname;
String image;
long Ptime;
String profile;
String Image;
String cuisine;
String where;
String locality;
int id;
String random;
String comment;
String reply;
double latitude,longitude;
int like;
int likecount;
int sharecount;
int commentid;
int commentcount;
int replycount;
int commentrepliesid;
int userid;
String city;
String username;
int present;
String followcheckinlists;

long timeofaction;
int idofpost;
String actionuserprofile;
int actionuserid;
String actionusername;
String usernameofpost;
String action;
String postimage;
String follow;
String FoodName;
String wherefrom;
long time;
int useridofpost;

public long getTime() {
return time;
}

public void setTime(long time) {
this.time = time;
}

public void setReplycount(int replycount) {
this.replycount = replycount;
}

public String getFoodName() {
return FoodName;
}

public void setFoodName(String foodName) {
FoodName = foodName;
}

protected descusers(Parcel in) {
descCrip = in.readString();
loginname = in.readString();
image = in.readString();
Ptime = in.readLong();
profile = in.readString();
Image = in.readString();
cuisine = in.readString();
where = in.readString();
locality = in.readString();
id = in.readInt();
random = in.readString();
comment = in.readString();
reply = in.readString();
city = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
like = in.readInt();
likecount = in.readInt();
sharecount = in.readInt();
commentid = in.readInt();
commentcount = in.readInt();
replycount = in.readInt();
commentrepliesid = in.readInt();
userid = in.readInt();
username = in.readString();
present = in.readInt();
followcheckinlists = in.readString();
timeofaction = in.readLong();
idofpost = in.readInt();
actionuserprofile = in.readString();
actionuserid = in.readInt();
actionusername = in.readString();
usernameofpost = in.readString();
action = in.readString();
postimage = in.readString();
follow = in.readString();
FoodName = in.readString();
wherefrom = in.readString();
time = in.readLong();
useridofpost = in.readInt();


}

public static final Creator<descusers> CREATOR = new Creator<descusers>() {
@Override
public descusers createFromParcel(Parcel in) {
return new descusers(in);
}

@Override
public descusers newArray(int size) {
return new descusers[size];
}
};

public int getUserid() {
return userid;
}

public void setUserid(int userid) {
this.userid = userid;
}

public void setPtime(long ptime) {
Ptime = ptime;
}



public void setProfile(String profile) {
this.profile = profile;
}


public String getProfile() {
return profile;
}




public int getCommentrepliesid() {
return commentrepliesid;
}

public descusers() {

}

public String getRandom() {
return random;
}

public void setRandom(String random) {
this.random = random;
}

public String getLoginname() {

return loginname;
}

public String getComment() {
return comment;
}


public String getDescCrip() {
return descCrip;
}

public void setDescCrip(String descCrip) {
this.descCrip = descCrip;
}

public int getCommentid() {
return commentid;
}

public void setCommentcount(int commentcount) {
this.commentcount = commentcount;
}

public int getCommentcount() {
return commentcount;
}

public void setSharecount(int sharecount) {
this.sharecount = sharecount;
}

public void setCity(String city) {
this.city = city;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public String getCity() {
return city;
}

public double getLatitude() {
return latitude;
}

public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {

this.longitude = longitude;
}

public String getReply() {
return reply;
}

public String getName(){
return loginname;
}

public String getCuisine() {
return cuisine;
}

public String getWhere() {
return where;
}

public void setLoginname(String loginname) {
this.loginname = loginname;
}

public String getLocality() {
return locality;
}

public String getimage() {
return image;
}

public void setimage(String image) {
this.image = image;
}

public void setId(int id) {
this.id = id;
}

public int getLikecount() {
return likecount;
}

public int getId() {

return id;

}

public void setLikecount(int likecount) {
this.likecount = likecount;
}

public void setLike(int like) {
this.like = like;

}

public void setCuisine(String cuisine) {
this.cuisine = cuisine;
}

public void setWhere(String where) {
this.where = where;
}

public void setLocality(String locality) {
this.locality = locality;
}

public int getLike() { return like; }

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}





public long getPtime() {
return Ptime;
}

@Override
public int describeContents() {
return 0;
}

public int getPresent() {
return present;
}

public void setPresent(int present) {
this.present = present;
}

public String getFollowcheckinlists() {
return followcheckinlists;
}

public long getTimeofaction() {
return timeofaction;
}

public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public void setTimeofaction(long timeofaction) {
this.timeofaction = timeofaction;
}

public int getIdofpost() {
return idofpost;
}

public void setIdofpost(int idofpost) {
this.idofpost = idofpost;
}

public String getActionuserprofile() {
return actionuserprofile;
}

public void setActionuserprofile(String actionuserprofile) {
this.actionuserprofile = actionuserprofile;
}

public int getActionuserid() {
return actionuserid;
}

public void setActionuserid(int actionuserid) {
this.actionuserid = actionuserid;
}

public String getActionusername() {
return actionusername;
}

public void setActionusername(String actionusername) {
this.actionusername = actionusername;
}

public String getUsernameofpost() {
return usernameofpost;
}

public void setUsernameofpost(String usernameofpost) {
this.usernameofpost = usernameofpost;
}

public String getPostimage() {
return postimage;
}

public void setPostimage(String postimage) {
this.postimage = postimage;
}

public void setFollowcheckinlists(String followcheckinlists) {
this.followcheckinlists = followcheckinlists;
}

public String getFollow() {
return follow;
}

public void setFollow(String follow) {
this.follow = follow;
}



@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(descCrip);
dest.writeString(loginname);
dest.writeString(image);
dest.writeLong(Ptime);
dest.writeString(profile);
dest.writeString(Image);
dest.writeString(cuisine);
dest.writeString(where);
dest.writeString(locality);
dest.writeInt(id);
dest.writeString(random);

dest.writeString(comment);
dest.writeString(reply);
dest.writeString(city);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeInt(like);

dest.writeInt(likecount);
dest.writeInt(sharecount);
dest.writeInt(commentid);
dest.writeInt(commentcount);
dest.writeInt(replycount);
dest.writeInt(commentrepliesid);
dest.writeInt(userid);
dest.writeString(username);

dest.writeInt(present);
dest.writeString(followcheckinlists);

dest.writeLong(timeofaction);
dest.writeInt(idofpost);
dest.writeString(actionuserprofile);
dest.writeInt(actionuserid);
dest.writeString(actionusername);
dest.writeString(usernameofpost);
dest.writeString(action);
dest.writeString(postimage);
dest.writeString(follow);
dest.writeString(FoodName);
dest.writeString(wherefrom);
dest.writeLong(time);
dest.writeInt(useridofpost);

}

}


Method used for getting response from server.



    private void listdisp(String query, String locationname, String uname, int id) {
m.mShimmerViewContainer.startShimmer();
m.mShimmerViewContainer.setVisibility(View.VISIBLE);

StringRequest stringRequest = new StringRequest(Request.Method.POST, BuildConfig.LD,
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
if (s != null && !s.isEmpty() && !s.equals("no results"))
{
Gson gson = new Gson();
m.dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());
FragmentActivity c = getActivity();
m.fpa = new followpostAdapter(c, m.dusers,m.user,m.s);
m.lists.setAdapter(m.fpa);
m.lists.setVisibility(View.VISIBLE);
// m.lists.setTextFilterEnabled(false);
// m.lists.setEmptyView(m.emptyElement);
m.mShimmerViewContainer.stopShimmer();
m.mShimmerViewContainer.setVisibility(View.GONE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {

@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new Hashtable<String, String>();
params.put("deskey", query);
params.put("uname",uname);
params.put("locationame",locationname);
params.put("userid",String.valueOf(id));
return params;
}
};
int socketTimeout = 60000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);

}






android gson android-gson






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 8:22

























asked Nov 20 at 8:07









user2269164

3001416




3001416












  • The error states that while you were expecting the Json to start with an array, it started with an object. If double check the received Json.
    – Fred
    Nov 20 at 8:12










  • It seems 'descusers' object is the problem.
    – H. Ekici
    Nov 20 at 8:14










  • Please post your pojo as well
    – Akshay Paliwal
    Nov 20 at 8:17










  • Posted POJO Classes and Volleymethod.
    – user2269164
    Nov 20 at 8:25


















  • The error states that while you were expecting the Json to start with an array, it started with an object. If double check the received Json.
    – Fred
    Nov 20 at 8:12










  • It seems 'descusers' object is the problem.
    – H. Ekici
    Nov 20 at 8:14










  • Please post your pojo as well
    – Akshay Paliwal
    Nov 20 at 8:17










  • Posted POJO Classes and Volleymethod.
    – user2269164
    Nov 20 at 8:25
















The error states that while you were expecting the Json to start with an array, it started with an object. If double check the received Json.
– Fred
Nov 20 at 8:12




The error states that while you were expecting the Json to start with an array, it started with an object. If double check the received Json.
– Fred
Nov 20 at 8:12












It seems 'descusers' object is the problem.
– H. Ekici
Nov 20 at 8:14




It seems 'descusers' object is the problem.
– H. Ekici
Nov 20 at 8:14












Please post your pojo as well
– Akshay Paliwal
Nov 20 at 8:17




Please post your pojo as well
– Akshay Paliwal
Nov 20 at 8:17












Posted POJO Classes and Volleymethod.
– user2269164
Nov 20 at 8:25




Posted POJO Classes and Volleymethod.
– user2269164
Nov 20 at 8:25












3 Answers
3






active

oldest

votes


















1














Problem is not with your model class, issue is with your response you are expecting array to come from api but it is actually coming as object under which you will have array, can you show code to understand more about it ?






share|improve this answer





















  • Please check my edit
    – user2269164
    Nov 20 at 8:25










  • Can you please add screenshot of your response you getting against your api call ?
    – Taha wakeel
    Nov 20 at 8:38










  • You can find it in my question.
    – user2269164
    Nov 20 at 8:52



















0














Instead of Json String request try to do it with Json Array Request that will return you Json Array






share|improve this answer























  • edits made to the question.
    – user2269164
    Nov 20 at 8:25












  • tested with JsonArrayRequest but same issue.
    – user2269164
    Nov 20 at 9:20



















0














The problem is with the POJO class. I have created a new class without extending or implementing any and able to extract the data using the Gson.



 public class d {

String FoodName;
String image;
String cuisine;
String wherefrom;
String locality;
int id;
int userid;
int likecount;
int sharecount;
String loginname;
String random;
int commentcount;
String city;
double latitude;
double longitude;
String profile;
long time;
int like;
String follow;

public String getFoodName() {
return FoodName;
}

public void setFoodName(String foodName) {
FoodName = foodName;
}

public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}

public String getCuisine() {
return cuisine;
}

public void setCuisine(String cuisine) {
this.cuisine = cuisine;
}

public String getWherefrom() {
return wherefrom;
}

public void setWherefrom(String wherefrom) {
this.wherefrom = wherefrom;
}

public String getLocality() {
return locality;
}

public void setLocality(String locality) {
this.locality = locality;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getUserid() {
return userid;
}

public void setUserid(int userid) {
this.userid = userid;
}

public int getLikecount() {
return likecount;
}

public void setLikecount(int likecount) {
this.likecount = likecount;
}

public int getSharecount() {
return sharecount;
}

public void setSharecount(int sharecount) {
this.sharecount = sharecount;
}

public String getLoginname() {
return loginname;
}

public void setLoginname(String loginname) {
this.loginname = loginname;
}

public String getRandom() {
return random;
}

public void setRandom(String random) {
this.random = random;
}

public int getCommentcount() {
return commentcount;
}

public void setCommentcount(int commentcount) {
this.commentcount = commentcount;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public double getLatitude() {
return latitude;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {
this.longitude = longitude;
}

public String getProfile() {
return profile;
}

public void setProfile(String profile) {
this.profile = profile;
}

public long getTime() {
return time;
}

public void setTime(long time) {
this.time = time;
}

public int getLike() {
return like;
}

public void setLike(int like) {
this.like = like;
}

public String getFollow() {
return follow;
}

public void setFollow(String follow) {
this.follow = follow;
}
}



Gson gson = new Gson();
ArrayList<d> da= gson.fromJson(s, new TypeToken<ArrayList<d>>() {}.getType());





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388649%2fcom-google-gson-jsonsyntaxexception-java-lang-illegalstateexception-expected-b%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Problem is not with your model class, issue is with your response you are expecting array to come from api but it is actually coming as object under which you will have array, can you show code to understand more about it ?






    share|improve this answer





















    • Please check my edit
      – user2269164
      Nov 20 at 8:25










    • Can you please add screenshot of your response you getting against your api call ?
      – Taha wakeel
      Nov 20 at 8:38










    • You can find it in my question.
      – user2269164
      Nov 20 at 8:52
















    1














    Problem is not with your model class, issue is with your response you are expecting array to come from api but it is actually coming as object under which you will have array, can you show code to understand more about it ?






    share|improve this answer





















    • Please check my edit
      – user2269164
      Nov 20 at 8:25










    • Can you please add screenshot of your response you getting against your api call ?
      – Taha wakeel
      Nov 20 at 8:38










    • You can find it in my question.
      – user2269164
      Nov 20 at 8:52














    1












    1








    1






    Problem is not with your model class, issue is with your response you are expecting array to come from api but it is actually coming as object under which you will have array, can you show code to understand more about it ?






    share|improve this answer












    Problem is not with your model class, issue is with your response you are expecting array to come from api but it is actually coming as object under which you will have array, can you show code to understand more about it ?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 at 8:12









    Taha wakeel

    896




    896












    • Please check my edit
      – user2269164
      Nov 20 at 8:25










    • Can you please add screenshot of your response you getting against your api call ?
      – Taha wakeel
      Nov 20 at 8:38










    • You can find it in my question.
      – user2269164
      Nov 20 at 8:52


















    • Please check my edit
      – user2269164
      Nov 20 at 8:25










    • Can you please add screenshot of your response you getting against your api call ?
      – Taha wakeel
      Nov 20 at 8:38










    • You can find it in my question.
      – user2269164
      Nov 20 at 8:52
















    Please check my edit
    – user2269164
    Nov 20 at 8:25




    Please check my edit
    – user2269164
    Nov 20 at 8:25












    Can you please add screenshot of your response you getting against your api call ?
    – Taha wakeel
    Nov 20 at 8:38




    Can you please add screenshot of your response you getting against your api call ?
    – Taha wakeel
    Nov 20 at 8:38












    You can find it in my question.
    – user2269164
    Nov 20 at 8:52




    You can find it in my question.
    – user2269164
    Nov 20 at 8:52













    0














    Instead of Json String request try to do it with Json Array Request that will return you Json Array






    share|improve this answer























    • edits made to the question.
      – user2269164
      Nov 20 at 8:25












    • tested with JsonArrayRequest but same issue.
      – user2269164
      Nov 20 at 9:20
















    0














    Instead of Json String request try to do it with Json Array Request that will return you Json Array






    share|improve this answer























    • edits made to the question.
      – user2269164
      Nov 20 at 8:25












    • tested with JsonArrayRequest but same issue.
      – user2269164
      Nov 20 at 9:20














    0












    0








    0






    Instead of Json String request try to do it with Json Array Request that will return you Json Array






    share|improve this answer














    Instead of Json String request try to do it with Json Array Request that will return you Json Array







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 20 at 8:28

























    answered Nov 20 at 8:11









    Rohit Sharma

    466413




    466413












    • edits made to the question.
      – user2269164
      Nov 20 at 8:25












    • tested with JsonArrayRequest but same issue.
      – user2269164
      Nov 20 at 9:20


















    • edits made to the question.
      – user2269164
      Nov 20 at 8:25












    • tested with JsonArrayRequest but same issue.
      – user2269164
      Nov 20 at 9:20
















    edits made to the question.
    – user2269164
    Nov 20 at 8:25






    edits made to the question.
    – user2269164
    Nov 20 at 8:25














    tested with JsonArrayRequest but same issue.
    – user2269164
    Nov 20 at 9:20




    tested with JsonArrayRequest but same issue.
    – user2269164
    Nov 20 at 9:20











    0














    The problem is with the POJO class. I have created a new class without extending or implementing any and able to extract the data using the Gson.



     public class d {

    String FoodName;
    String image;
    String cuisine;
    String wherefrom;
    String locality;
    int id;
    int userid;
    int likecount;
    int sharecount;
    String loginname;
    String random;
    int commentcount;
    String city;
    double latitude;
    double longitude;
    String profile;
    long time;
    int like;
    String follow;

    public String getFoodName() {
    return FoodName;
    }

    public void setFoodName(String foodName) {
    FoodName = foodName;
    }

    public String getImage() {
    return image;
    }

    public void setImage(String image) {
    this.image = image;
    }

    public String getCuisine() {
    return cuisine;
    }

    public void setCuisine(String cuisine) {
    this.cuisine = cuisine;
    }

    public String getWherefrom() {
    return wherefrom;
    }

    public void setWherefrom(String wherefrom) {
    this.wherefrom = wherefrom;
    }

    public String getLocality() {
    return locality;
    }

    public void setLocality(String locality) {
    this.locality = locality;
    }

    public int getId() {
    return id;
    }

    public void setId(int id) {
    this.id = id;
    }

    public int getUserid() {
    return userid;
    }

    public void setUserid(int userid) {
    this.userid = userid;
    }

    public int getLikecount() {
    return likecount;
    }

    public void setLikecount(int likecount) {
    this.likecount = likecount;
    }

    public int getSharecount() {
    return sharecount;
    }

    public void setSharecount(int sharecount) {
    this.sharecount = sharecount;
    }

    public String getLoginname() {
    return loginname;
    }

    public void setLoginname(String loginname) {
    this.loginname = loginname;
    }

    public String getRandom() {
    return random;
    }

    public void setRandom(String random) {
    this.random = random;
    }

    public int getCommentcount() {
    return commentcount;
    }

    public void setCommentcount(int commentcount) {
    this.commentcount = commentcount;
    }

    public String getCity() {
    return city;
    }

    public void setCity(String city) {
    this.city = city;
    }

    public double getLatitude() {
    return latitude;
    }

    public void setLatitude(double latitude) {
    this.latitude = latitude;
    }

    public double getLongitude() {
    return longitude;
    }

    public void setLongitude(double longitude) {
    this.longitude = longitude;
    }

    public String getProfile() {
    return profile;
    }

    public void setProfile(String profile) {
    this.profile = profile;
    }

    public long getTime() {
    return time;
    }

    public void setTime(long time) {
    this.time = time;
    }

    public int getLike() {
    return like;
    }

    public void setLike(int like) {
    this.like = like;
    }

    public String getFollow() {
    return follow;
    }

    public void setFollow(String follow) {
    this.follow = follow;
    }
    }



    Gson gson = new Gson();
    ArrayList<d> da= gson.fromJson(s, new TypeToken<ArrayList<d>>() {}.getType());





    share|improve this answer


























      0














      The problem is with the POJO class. I have created a new class without extending or implementing any and able to extract the data using the Gson.



       public class d {

      String FoodName;
      String image;
      String cuisine;
      String wherefrom;
      String locality;
      int id;
      int userid;
      int likecount;
      int sharecount;
      String loginname;
      String random;
      int commentcount;
      String city;
      double latitude;
      double longitude;
      String profile;
      long time;
      int like;
      String follow;

      public String getFoodName() {
      return FoodName;
      }

      public void setFoodName(String foodName) {
      FoodName = foodName;
      }

      public String getImage() {
      return image;
      }

      public void setImage(String image) {
      this.image = image;
      }

      public String getCuisine() {
      return cuisine;
      }

      public void setCuisine(String cuisine) {
      this.cuisine = cuisine;
      }

      public String getWherefrom() {
      return wherefrom;
      }

      public void setWherefrom(String wherefrom) {
      this.wherefrom = wherefrom;
      }

      public String getLocality() {
      return locality;
      }

      public void setLocality(String locality) {
      this.locality = locality;
      }

      public int getId() {
      return id;
      }

      public void setId(int id) {
      this.id = id;
      }

      public int getUserid() {
      return userid;
      }

      public void setUserid(int userid) {
      this.userid = userid;
      }

      public int getLikecount() {
      return likecount;
      }

      public void setLikecount(int likecount) {
      this.likecount = likecount;
      }

      public int getSharecount() {
      return sharecount;
      }

      public void setSharecount(int sharecount) {
      this.sharecount = sharecount;
      }

      public String getLoginname() {
      return loginname;
      }

      public void setLoginname(String loginname) {
      this.loginname = loginname;
      }

      public String getRandom() {
      return random;
      }

      public void setRandom(String random) {
      this.random = random;
      }

      public int getCommentcount() {
      return commentcount;
      }

      public void setCommentcount(int commentcount) {
      this.commentcount = commentcount;
      }

      public String getCity() {
      return city;
      }

      public void setCity(String city) {
      this.city = city;
      }

      public double getLatitude() {
      return latitude;
      }

      public void setLatitude(double latitude) {
      this.latitude = latitude;
      }

      public double getLongitude() {
      return longitude;
      }

      public void setLongitude(double longitude) {
      this.longitude = longitude;
      }

      public String getProfile() {
      return profile;
      }

      public void setProfile(String profile) {
      this.profile = profile;
      }

      public long getTime() {
      return time;
      }

      public void setTime(long time) {
      this.time = time;
      }

      public int getLike() {
      return like;
      }

      public void setLike(int like) {
      this.like = like;
      }

      public String getFollow() {
      return follow;
      }

      public void setFollow(String follow) {
      this.follow = follow;
      }
      }



      Gson gson = new Gson();
      ArrayList<d> da= gson.fromJson(s, new TypeToken<ArrayList<d>>() {}.getType());





      share|improve this answer
























        0












        0








        0






        The problem is with the POJO class. I have created a new class without extending or implementing any and able to extract the data using the Gson.



         public class d {

        String FoodName;
        String image;
        String cuisine;
        String wherefrom;
        String locality;
        int id;
        int userid;
        int likecount;
        int sharecount;
        String loginname;
        String random;
        int commentcount;
        String city;
        double latitude;
        double longitude;
        String profile;
        long time;
        int like;
        String follow;

        public String getFoodName() {
        return FoodName;
        }

        public void setFoodName(String foodName) {
        FoodName = foodName;
        }

        public String getImage() {
        return image;
        }

        public void setImage(String image) {
        this.image = image;
        }

        public String getCuisine() {
        return cuisine;
        }

        public void setCuisine(String cuisine) {
        this.cuisine = cuisine;
        }

        public String getWherefrom() {
        return wherefrom;
        }

        public void setWherefrom(String wherefrom) {
        this.wherefrom = wherefrom;
        }

        public String getLocality() {
        return locality;
        }

        public void setLocality(String locality) {
        this.locality = locality;
        }

        public int getId() {
        return id;
        }

        public void setId(int id) {
        this.id = id;
        }

        public int getUserid() {
        return userid;
        }

        public void setUserid(int userid) {
        this.userid = userid;
        }

        public int getLikecount() {
        return likecount;
        }

        public void setLikecount(int likecount) {
        this.likecount = likecount;
        }

        public int getSharecount() {
        return sharecount;
        }

        public void setSharecount(int sharecount) {
        this.sharecount = sharecount;
        }

        public String getLoginname() {
        return loginname;
        }

        public void setLoginname(String loginname) {
        this.loginname = loginname;
        }

        public String getRandom() {
        return random;
        }

        public void setRandom(String random) {
        this.random = random;
        }

        public int getCommentcount() {
        return commentcount;
        }

        public void setCommentcount(int commentcount) {
        this.commentcount = commentcount;
        }

        public String getCity() {
        return city;
        }

        public void setCity(String city) {
        this.city = city;
        }

        public double getLatitude() {
        return latitude;
        }

        public void setLatitude(double latitude) {
        this.latitude = latitude;
        }

        public double getLongitude() {
        return longitude;
        }

        public void setLongitude(double longitude) {
        this.longitude = longitude;
        }

        public String getProfile() {
        return profile;
        }

        public void setProfile(String profile) {
        this.profile = profile;
        }

        public long getTime() {
        return time;
        }

        public void setTime(long time) {
        this.time = time;
        }

        public int getLike() {
        return like;
        }

        public void setLike(int like) {
        this.like = like;
        }

        public String getFollow() {
        return follow;
        }

        public void setFollow(String follow) {
        this.follow = follow;
        }
        }



        Gson gson = new Gson();
        ArrayList<d> da= gson.fromJson(s, new TypeToken<ArrayList<d>>() {}.getType());





        share|improve this answer












        The problem is with the POJO class. I have created a new class without extending or implementing any and able to extract the data using the Gson.



         public class d {

        String FoodName;
        String image;
        String cuisine;
        String wherefrom;
        String locality;
        int id;
        int userid;
        int likecount;
        int sharecount;
        String loginname;
        String random;
        int commentcount;
        String city;
        double latitude;
        double longitude;
        String profile;
        long time;
        int like;
        String follow;

        public String getFoodName() {
        return FoodName;
        }

        public void setFoodName(String foodName) {
        FoodName = foodName;
        }

        public String getImage() {
        return image;
        }

        public void setImage(String image) {
        this.image = image;
        }

        public String getCuisine() {
        return cuisine;
        }

        public void setCuisine(String cuisine) {
        this.cuisine = cuisine;
        }

        public String getWherefrom() {
        return wherefrom;
        }

        public void setWherefrom(String wherefrom) {
        this.wherefrom = wherefrom;
        }

        public String getLocality() {
        return locality;
        }

        public void setLocality(String locality) {
        this.locality = locality;
        }

        public int getId() {
        return id;
        }

        public void setId(int id) {
        this.id = id;
        }

        public int getUserid() {
        return userid;
        }

        public void setUserid(int userid) {
        this.userid = userid;
        }

        public int getLikecount() {
        return likecount;
        }

        public void setLikecount(int likecount) {
        this.likecount = likecount;
        }

        public int getSharecount() {
        return sharecount;
        }

        public void setSharecount(int sharecount) {
        this.sharecount = sharecount;
        }

        public String getLoginname() {
        return loginname;
        }

        public void setLoginname(String loginname) {
        this.loginname = loginname;
        }

        public String getRandom() {
        return random;
        }

        public void setRandom(String random) {
        this.random = random;
        }

        public int getCommentcount() {
        return commentcount;
        }

        public void setCommentcount(int commentcount) {
        this.commentcount = commentcount;
        }

        public String getCity() {
        return city;
        }

        public void setCity(String city) {
        this.city = city;
        }

        public double getLatitude() {
        return latitude;
        }

        public void setLatitude(double latitude) {
        this.latitude = latitude;
        }

        public double getLongitude() {
        return longitude;
        }

        public void setLongitude(double longitude) {
        this.longitude = longitude;
        }

        public String getProfile() {
        return profile;
        }

        public void setProfile(String profile) {
        this.profile = profile;
        }

        public long getTime() {
        return time;
        }

        public void setTime(long time) {
        this.time = time;
        }

        public int getLike() {
        return like;
        }

        public void setLike(int like) {
        this.like = like;
        }

        public String getFollow() {
        return follow;
        }

        public void setFollow(String follow) {
        this.follow = follow;
        }
        }



        Gson gson = new Gson();
        ArrayList<d> da= gson.fromJson(s, new TypeToken<ArrayList<d>>() {}.getType());






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 6:32









        user2269164

        3001416




        3001416






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388649%2fcom-google-gson-jsonsyntaxexception-java-lang-illegalstateexception-expected-b%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy