- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个如下所示的 json 输出。
[{"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"}]
我在 Volley 中使用 StringRequest 来获取响应。我正在使用 Gson 库进行解析,并且工作正常。但突然我收到以下错误。
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]
我不确定哪里出了问题。下面会提到用于解析的Gson代码。
Gson gson = new Gson();
ArrayList<descusers> dusers = gson.fromJson(s, new TypeToken<ArrayList<descusers>>() {}.getType());
s 是我的回应。我已经交叉检查了 descusers 中的所有值,并且变量都匹配。请帮忙。
清理并重建项目但没有用。它错误地提到了 path.$[0] 并且我不确定它指向哪些对象。
我的 POJO 类:
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);
}
}
用于从服务器获取响应的方法。
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);
}
最佳答案
问题不在于您的模型类,问题在于您的响应,您期望数组来自 api 但它实际上是作为对象出现的,您将在其下拥有数组,您可以显示代码以了解更多信息吗?
关于android - com.google.gson.JsonSyntaxException : java. lang.IllegalStateException:应为 BEGIN_ARRAY 但在第 1 行第 3 列路径 $[0] 处为 BEGIN_OBJECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53388649/
在 Tomcat 6/Ubuntu 12.04 上启动 Grails 2.1.0 应用程序时出现以下错误。 Error 500 - Internal Server Error. groovy.lang
在运行 Storm 拓扑时,我收到此错误。拓扑完美运行 5 分钟,没有任何错误,然后失败。我正在使用 Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS as 300 sec i
我有一个 jsp 代码在其中一台机器上运行良好。但是当我复制到另一台机器时,我得到了这个 no such method found 异常。我是 Spring 的新手。有人可以解释我错过了什么吗? 以下
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我的代码在下面给出了一个错误; Exception in thread "main" java.lang.NoSuchMethodError: com/myApp/Client.cypherCBC(L
我正在尝试一个 Restful web 服务示例,所以当我要访问 url 时,我遇到了异常 java.lang.NoSuchMethodError: jersey.repackaged.com.goo
我正在将一个 Spring web 项目转换为一个 Maven 项目,但我收到了这个错误: java.lang.NoSuchMethodError: org.jboss.logging.Logger.
在我的项目中,我有一个像这样的枚举: public enum MyEnum { FIRST(1), SECOND(2); private int value; private MyEnum(int v
我创建了这个简单的示例,用于读取 Linux 正常运行时间: public String getMachineUptime() throws IOException { String[] di
我正在使用 Eclipse,并且正在使用 Java。我的目标是使用 bogoSort 方法对 vector 进行排序在一个 vector (vectorExample)中适应我的 vector 类型,
我正在运行以下查询。它显示一条错误消息。如何解决这个错误? ListrouteList=null; List companyList = session.createS
我有以下模型类: @Entity @Table(name="user_content") @org.hibernate.annotations.NamedQueries({ @org.
我有那个错误。这是我的代码: GmailSettingsService service = new GmailSettingsService(APPLICATION_NAME, DOMAIN_NAME
实际上我在执行我的java程序时遇到了下面提到的错误 Exception in thread "pool-1-thread-1" java.lang.ClassCastException: jav
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String 我在以下代码中遇到此异常: Strin
我正在尝试从 linkedhashset 中检索随机元素。下面是我的代码,但它每次都给我异常。 private static void generateRandomUserId(Set userIds
我已经完成了 Android 中的代码: List spinnerArray = new ArrayList(); for (int i = 0; i item = (LinkedTreeMap)
这个问题已经有答案了: Explanation of ClassCastException in Java (12 个回答) 已关闭 6 年前。 我已经编写了 java 到 Json 的代码,同时从页
这个问题在这里已经有了答案: ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn (4 个答案) 关闭 6 年前
我在运行时遇到问题来编译这段代码,这给我一个错误,java.lang.Integer 无法转换为 Java.lang.Double。如果有人帮助我更正此代码,我将非常高兴 double x; pu
我是一名优秀的程序员,十分优秀!