gpt4 book ai didi

android - 需要一个字符串,但在 $.Result 处是 BEGIN_OBJECT

转载 作者:行者123 更新时间:2023-11-29 01:20:57 25 4
gpt4 key购买 nike

我有两个响应成功和失败我的 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: 预期为 BEGIN_OBJECT 但在第 1 行第 75 列路径 $.Result 中为 STRING我正在使用改造库我的模型类

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");
}
});

最佳答案

查看您的失败响应。

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

看到 Result 是一个字符串而不是一个 JSON 对象了吗?

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

您的模型不一致,这是您的问题。

关于android - 需要一个字符串,但在 $.Result 处是 BEGIN_OBJECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36837351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com