预期为BEGIN_OBJECT,但在第1行第2列路径$ .data

时间:2018-07-05 06:32:43

标签: parsing gson retrofit

使用Gson库解析json时出错

我正在尝试使用Gson库来解析api响应。这是响应字符串:

 {
    "results": {
        "sessiondata": {
            "user_id": 25,
            "usertype": "admin",
            "login_string": "",
            "idlogin_track": 88
        },
        "logged_emp": {
            "accesscode": 5764589930814636031,
            "writecode": 5764589930814636031,
            "role": "Administrator",
            "fullname": "Divya Saddi",
            "email": "divya@gmail.com",
            "contactno": " - N/A - ",
            "pwd": "",
            "uname": "",
            "user_id": 25,
            "usertype": "admin",
            "idlogin_track": 88,
            "login_string": "",
            "leaverequestto": "",
            "lastlogin": ""
        }
    }
}

使用Retrofit GsonConversionFactory,它显示错误。 我正在尝试阅读回复。进入Pojo类:

公共类MyPojo {私人搜寻结果;     公共结果getResults()     {返回结果; }     public void setResults(结果结果)     {this.results = results;} }

结果类

public class Results
{
    private Sessiondata sessiondata;

    private Logged_emp logged_emp;

    public Sessiondata getSessiondata ()
    {
        return sessiondata;
    }

    public void setSessiondata (Sessiondata sessiondata)
    {
        this.sessiondata = sessiondata;
    }

    public Logged_emp getLogged_emp ()
    {
        return logged_emp;
    }

    public void setLogged_emp (Logged_emp logged_emp)
    {
        this.logged_emp = logged_emp;
    }


}

会话课程

public class Sessiondata
{
    private String login_string;

    private String usertype;

    private int user_id;

    private int idlogin_track;

    public String getLogin_string ()
    {
        return login_string;
    }

    public void setLogin_string (String login_string)
    {
        this.login_string = login_string;
    }

    public String getUsertype ()
    {
        return usertype;
    }

    public void setUsertype (String usertype)
    {
        this.usertype = usertype;
    }

    public int getUser_id ()
    {
        return user_id;
    }

    public void setUser_id (int user_id)
    {
        this.user_id = user_id;
    }

    public int getIdlogin_track ()
    {
        return idlogin_track;
    }

    public void setIdlogin_track (int idlogin_track)
    {
        this.idlogin_track = idlogin_track;
    }


}

记录的Emp

public class Logged_emp
{
    private String leaverequestto;

    private String login_string;

    private String pwd;

    private long writecode;

    private String email;

    private String uname;

    private String lastlogin;

    private String role;

    private String usertype;

    private int user_id;

    private String contactno;

    private String fullname;

    private int idlogin_track;

    private long accesscode;

    public String getLeaverequestto ()
    {
        return leaverequestto;
    }

    public void setLeaverequestto (String leaverequestto)
    {
        this.leaverequestto = leaverequestto;
    }

    public String getLogin_string ()
    {
        return login_string;
    }

    public void setLogin_string (String login_string)
    {
        this.login_string = login_string;
    }

    public String getPwd ()
    {
        return pwd;
    }

    public void setPwd (String pwd)
    {
        this.pwd = pwd;
    }

    public long getWritecode ()
    {
        return writecode;
    }

    public void setWritecode (long writecode)
    {
        this.writecode = writecode;
    }

    public String getEmail ()
    {
        return email;
    }

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

    public String getUname ()
    {
        return uname;
    }

    public void setUname (String uname)
    {
        this.uname = uname;
    }

    public String getLastlogin ()
    {
        return lastlogin;
    }

    public void setLastlogin (String lastlogin)
    {
        this.lastlogin = lastlogin;
    }

    public String getRole ()
    {
        return role;
    }

    public void setRole (String role)
    {
        this.role = role;
    }

    public String getUsertype ()
    {
        return usertype;
    }

    public void setUsertype (String usertype)
    {
        this.usertype = usertype;
    }

    public int getUser_id ()
    {
        return user_id;
    }

    public void setUser_id (int user_id)
    {
        this.user_id = user_id;
    }

    public String getContactno ()
    {
        return contactno;
    }

    public void setContactno (String contactno)
    {
        this.contactno = contactno;
    }

    public String getFullname ()
    {
        return fullname;
    }

    public void setFullname (String fullname)
    {
        this.fullname = fullname;
    }

    public int getIdlogin_track ()
    {
        return idlogin_track;
    }

    public void setIdlogin_track (int idlogin_track)
    {
        this.idlogin_track = idlogin_track;
    }

    public long getAccesscode ()
    {
        return accesscode;
    }

    public void setAccesscode (long accesscode)
    {
        this.accesscode = accesscode;
    }


}

0 个答案:

没有答案