期望一个字符串但是$ .Result的BEGIN_OBJECT

时间:2016-04-25 09:58:05

标签: android

我得到两个回复成功并失败 我的json成功回应

{
  "Status": 1,
  "Message": "records are available",
  "Result": {
    "id": 10135,
    "email": "payal@demo.in",
    "mobile": "8545324342",
    "first_name": "xyz1",
    "last_name": null,
    "vendor_type_id": 1,
    "status": "A",
    "subscription_name": "free",
    "profile_Image": null,
    "attempt_date": "2016-04-23T12:15:56.4815954"
  }
}

我的json失败回复

 {"Status":0,"Message":"please enter correct email and password","Result":""}

日志消息: FailResponseretrofit.RetrofitError:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:Expected BEGIN_OBJECT但是STRING在第1行第75列路径$ .Result 我正在使用改造库 我的模特课

public class LoginBean {
    private String Status;
private String Message;

private ResultLogin Result;

public String getStatus() {
    return Status;
}

public void setStatus(String status) {
    Status = status;
}

public String getMessage() {
    return Message;
}

public void setMessage(String message) {
    Message = message;
}

public ResultLogin getResult() {
    return Result;
}

public void setResult(ResultLogin result) {
    Result = result;
}

public class ResultLogin{

    private String  id;

    private String  email;

    private String  mobile;

    private String  first_name;

    private String  last_name;

    private String  vendor_type_id;

    private String  status;

    private String  subscription_name;

    public String getId() {
        return id;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getFirst_name() {
        return first_name;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public String getVendor_type_id() {
        return vendor_type_id;
    }

    public void setVendor_type_id(String vendor_type_id) {
        this.vendor_type_id = vendor_type_id;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getSubscription_name() {
        return subscription_name;
    }

    public void setSubscription_name(String subscription_name) {
        this.subscription_name = subscription_name;
    }
}

}

我的java代码

如何解析json对象数据中的json数据

RestClient.post().pharmacyLogin(etEmail.getText().toString(), etPassword.getText().toString(), new Callback<LoginBean>() {
        @Override
        public void success(LoginBean loginBean, Response response) {
            //Log.d("Success", "Response" + response);
            try {
                // dialog.dismiss();
                Status = loginBean.getStatus();
                Message = loginBean.getMessage();
                String id = loginBean.getResult().getId();

                System.out.println("LoginResponse" + Status + "--" + Message + "--" + id);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void failure(RetrofitError error) {
            Log.d("Success", "FailResponse" + error);
            //AppConstants.showToastMessage(getApplication(), "Wrong Login Detail");
        }
    });

2 个答案:

答案 0 :(得分:1)

看看你的失败回应。

 {"Status":0,"Message":"please enter correct email and password","Result":""}

查看Result是字符串而不是JSON对象?

它是您成功响应中的JSON对象。

你的模型不一致,那就是你的问题。

答案 1 :(得分:0)

我的回复有一些字符串,但你试图将其用作对象,这就是为什么会出现这样的错误