当前位置: 代码迷 >> Android >> Android-Expected a string but was BEGIN_ARRAY at line 一 column 50
  详细解决方案

Android-Expected a string but was BEGIN_ARRAY at line 一 column 50

热度:45   发布时间:2016-04-27 23:16:54.0
Android-Expected a string but was BEGIN_ARRAY at line 1 column 50

今天在用bmob的时候,报了“Expected a string but was BEGIN_ARRAY at line 1 column 50“这个错误,开始我没有注意,以为是网络引起的错误,后来总是报错,所以仔细看了一下,期待一个String类型却是一个array类型,心想,这肯定报错啊。
传回来的是json数据,映射到这个实体类。

public class Notice extends BmobObject{    private String name;    private String image;    private String desc;    private String url;    private String function;    private String type;    private String[] functions;    private String[] foodInfos;    private BmobRelation steps;    private BmobRelation condiments;    下面省略setter getter方法。。。}

注意functions,foodInfos两个字段。
json返回的数据是{“xxx”:”xxx”….,”functions”:”{[1],[2],[3]}”,”foodInfos”:”{[1],[2],[3]}”,”xxxx”:”xxxx”}
返回的是array。问题找到了。动手解决。如果是使用Gson的话,就按照下面,我现在用的bmob,果然是比较受限了,必须得修改数据,符合字段要求。

public class Notice extends BmobObject{    private String name;    private String image;    private String desc;    private String url;    private String function;    private String type;    private List<String> functions;    private List<String> foodInfos;    private BmobRelation steps;    private BmobRelation condiments;    下面省略setter getter方法。。。}

版权声明:本文为博主原创文章,未经博主允许不得转载。

  相关解决方案