android预计BEGIN_OBJECT但在第1行第1列是STRING

时间:2018-01-29 05:42:16

标签: android gson retrofit

预计BEGIN_OBJECT但在第1行第1列是STRING Ocuure Illigal语句异常和JsonSyntaxException

这是我的RegisterFragment中的内容:

User user = new User();
        user.setName(name);
        user.setEmail(email);
        user.setPassword(password);
registerProcess(user);

 private void registerProcess(User user) {

    mSubscriptions.add(NetworkUtil.getRetrofit().register(user)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(this::handleResponse, this::handleError));
}
private void handleResponse(MyResponse response) {

    mProgressbar.setVisibility(View.GONE);
    showSnackBarMessage(response.getMessage());
}

private void handleError(Throwable error){

    mProgressbar.setVisibility(View.GONE);

    if (error instanceof HttpException) {

        Gson gson = new GsonBuilder().create();

        try {

            String errorBody = ((HttpException) error).response().errorBody().string();
            MyResponse response = gson.fromJson(errorBody, MyResponse.class);
           Log.i(TAG, "handleError: "+ response.getMessage());
            showSnackBarMessage(response.getMessage());

        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {

        showSnackBarMessage("Network Error !");
    }
}

0 个答案:

没有答案