十年燈
2018-04-13 09:01
采纳率: 28.6%
浏览 2.5k

retrofit请求获取返回值错误

retrofit请求获取返回值的时候retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 37 path $.data

 进行请求的
((App) getApplication()).getApi().updateAuthorization(access_token, nonce, timestamp, userCode, sign, userPhone, type, approvalinfo, modelIds, new Callback<AuthorityListEntity>() {
                @Override
                public void success(AuthorityListEntity authorityListEntity, Response response) {
                    if (authorityListEntity.getMessage() != null) {
                        if (authorityListEntity.isSuccess()) {
                            failed(getResources().getString(R.string.authorizesucces));
                        } else {
                            String message = authorityListEntity.getMessage();
                            if ("超时了".equals(message)) {
                                String nonce = NetWorkUtil.getNonce();
                                String timestamp = NetWorkUtil.getTimestamp();
                                String refreshToken = SharedPreferencesUtils.getString(context, Constants.REFRESHTOKEN, "");
                                String code = SharedPreferencesUtils.getString(context, Constants.USERCODE, "");
                                String sign = new Md5().getMD5ofStr("refreshToken" + "=" + refreshToken + "&" + "userCode" + "=" + code + Constants.SIGNMANTISSA).toLowerCase();
                                refresh_1(nonce, timestamp, sign, refreshToken, code);
                            } else {
                                if (!TextUtils.isEmpty(message)) {
                                    failed(MessageUtils.setMessage(context, message));
                                }
                            }
                        }

返回值

 {"accountOperationType":"2","data":{},"message":"编辑授权成功","modelIds":null,"page":0,"success":true,"total":0,"totalPages":0}

下面是bean

public class AuthorityListEntity {

    private String message;
    private int page;
    private boolean success;
    private int total;
    private String accountOperationType;
    private List<String> modelIds;
    private List<DataBean> data;
    private int totalPages;

    public List<String> getModelIds() {
        return modelIds;
    }

    public void setModelIds(List<String> modelIds) {
        this.modelIds = modelIds;
    }

    public String getAccountOperationType() {
        return accountOperationType;
    }

    public void setAccountOperationType(String accountOperationType) {
        this.accountOperationType = accountOperationType;
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public class DataBean {
        private String userPhone;
        private String deviceAddress;
        private int deviceNum;
        private String name;
        private String icon;
        private String isAuthorited;
        private String roomCode;
        private String deviceCode;
        private String type;
        private String userCode;
        private String accountOperationType;
        private String validationCode;

        public String getAccountOperationType() {
            return accountOperationType;
        }

        public void setAccountOperationType(String accountOperationType) {
            this.accountOperationType = accountOperationType;
        }

        public String getValidationCode() {
            return validationCode;
        }

        public void setValidationCode(String validationCode) {
            this.validationCode = validationCode;
        }

        public String getUserPhone() {
            return userPhone;
        }

        public void setUserPhone(String userPhone) {
            this.userPhone = userPhone;
        }

        public String getDeviceAddress() {
            return deviceAddress;
        }

        public void setDeviceAddress(String deviceAddress) {
            this.deviceAddress = deviceAddress;
        }

        public int getDeviceNum() {
            return deviceNum;
        }

        public void setDeviceNum(int deviceNum) {
            this.deviceNum = deviceNum;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getIsAuthorited() {
            return isAuthorited;
        }

        public void setIsAuthorited(String isAuthorited) {
            this.isAuthorited = isAuthorited;
        }

        public String getRoomCode() {
            return roomCode;
        }

        public void setRoomCode(String roomCode) {
            this.roomCode = roomCode;
        }

        public String getDeviceCode() {
            return deviceCode;
        }

        public void setDeviceCode(String deviceCode) {
            this.deviceCode = deviceCode;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getUserCode() {
            return userCode;
        }

        public void setUserCode(String userCode) {
            this.userCode = userCode;
        }
    }
}

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • Sloth-er 2018-04-13 09:32
    已采纳

    {"accountOperationType":"2"**,"data":{},**"message":"编辑授权成功","modelIds":null,"page":0,"success":true,"total":0,"totalPages":0}

    data域的返回值错误,{}应该改成【】

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 大白鲨鱼 2018-04-13 09:27

    com.google.gson.JsonSyntaxException可以发现是Json的问题,把数据拿到在线JSON工具检测一下,看是否有错误

    评论
    解决 无用
    打赏 举报
  • 键盘舞者113 2018-04-13 13:02

    把返回的Gson字段放在在线Gson字段转java bean类的工具
    http://www.atool.org/json2javabean.php

    评论
    解决 无用
    打赏 举报
  • shouniezhe 2018-04-26 14:38

    使用 https://www.json.cn/ 可以在线对jso数据进行解析, json数据中 {} 表示对象, []表示集合

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题