-2

Hi I have following json response, I am not able to access data of 'edit' jsonobject, how to create pojo for that?

Example

{
    "result":"",
    "responseMessage":"",
    "edit":{
        "id":"156",
        "user_id":"5466",

    },
    "data":[
         {
            "dataid":"1",
            "dataname":"tt"
        },
        {
            "dataid":"2",
            "dataname":"tt"
        }
    ]
}

How to create pojo class for this response

AwaisMajeed
  • 2,254
  • 2
  • 10
  • 25
Nilima
  • 75
  • 1
  • 10

2 Answers2

1

your Json is incorrect. There is an extra "," inside edit object. Remove that and try accessing data of edit

Still if you are unable to access, I am attaching following POJO for you to use.

public class ExPojo
{
    private String responseMessage;

    private String result;

    private Data[] data;

    private Edit edit;

    public String getResponseMessage ()
    {
        return responseMessage;
    }

    public void setResponseMessage (String responseMessage)
    {
        this.responseMessage = responseMessage;
    }

    public String getResult ()
    {
        return result;
    }

    public void setResult (String result)
    {
        this.result = result;
    }

    public Data[] getData ()
    {
        return data;
    }

    public void setData (Data[] data)
    {
        this.data = data;
    }

    public Edit getEdit ()
    {
        return edit;
    }

    public void setEdit (Edit edit)
    {
        this.edit = edit;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [responseMessage = "+responseMessage+", result = "+result+", data = "+data+", edit = "+edit+"]";
    }
}

Hope this helps.

Molly
  • 1,887
  • 3
  • 17
  • 34
1

You can use this link to create POJO classes for your JSON in future. However your JSON is also not valid, it contains an extra , in your edit object.

"edit":{
    "id":"156",
    "user_id":"5466",<--This comma

}
AwaisMajeed
  • 2,254
  • 2
  • 10
  • 25