-2

My JSON is as follows,

[{
    "0": {
        "id": "1",
        "first_name": "Super",
        "last_name": "Admin",
        "email": "super@admin.com",
        "password": "12345",
        "mobile_no": "9811657128",
        "parent_id": "0",
        "position": "0",
        "type": "super",
        "created_at": null,
        "updated_at": null,
        "deleted_at": null,
        "stage": 0,
        "total_childs": 5
    },
    "11": {
        "id": "52",
        "first_name": "Ashish",
        "last_name": "Chauhan",
        "email": "ashish@mlm.com",
        "password": "12345",
        "mobile_no": "89889989832",
        "parent_id": "8",
        "position": "1",
        "type": "admin",
        "created_at": "1476702542",
        "updated_at": "1476702542",
        "deleted_at": null,
        "stage": 0,
        "total_childs": 0
    }
}, {
    "0": {
        "id": "2",
        "first_name": "Ashish",
        "last_name": "Chauhan",
        "email": "ashish@mlm.com",
        "password": "12345",
        "mobile_no": "89889989832",
        "parent_id": "1",
        "position": "0",
        "type": "admin",
        "created_at": "1475674631",
        "updated_at": "1475674631",
        "deleted_at": null,
        "stage": 2,
        "total_childs": 2
    }
}, {
    "0": {
        "id": "7",
        "first_name": "Shiva",
        "last_name": "Singh",
        "email": "shiva@mlm.com",
        "password": "12345",
        "mobile_no": "89889989832",
        "parent_id": "2",
        "position": "0",
        "type": "user",
        "created_at": "1475674808",
        "updated_at": "1475674808",
        "deleted_at": null,
        "stage": 1,
        "total_childs": 2
    },
    "1": {
        "id": "8",
        "first_name": "Atul",
        "last_name": "Kumar",
        "email": "atul@mlm.com",
        "password": "12345",
        "mobile_no": "89889989832",
        "parent_id": "2",
        "position": "1",
        "type": "user",
        "created_at": "1475674835",
        "updated_at": "1475674835",
        "deleted_at": null,
        "stage": 1,
        "total_childs": 2
    }
}]
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
  • use http://www.jsonschema2pojo.org/ – Divyang Panchal Oct 27 '16 at 08:15
  • sir please once check yourself....how will handle with object 0,1,2..... – prasant pandey Oct 27 '16 at 08:22
  • `how to pojo of my json response please help my response like this` Not able to understand your problem from this. Are you trying to convert json to POJO? – so-random-dude Oct 27 '16 at 08:23
  • sir i have to fetch data using retrofit..but problem is that how i will deal with object 0,1,2... getter and setter to get data from object 0,1,2,3.... – prasant pandey Oct 27 '16 at 08:26
  • 2
    possible duplicate of [this](http://stackoverflow.com/questions/40255024/how-to-make-pojo-class-for-json/40255438#40255438). Is he your friend/brother? Are you guys doing homework on stackoverflow? Please check the site properly before posting anything. – Rushi M Thakker Oct 27 '16 at 08:28

2 Answers2

0

Make use of SerializedName from Gson lib :

public class myPojo{

  @SerializedName("0")
  private String one;

  @SerializedName("1")
  private String two;

  .....
}
ramji
  • 1,982
  • 2
  • 13
  • 13
0

Make a Java class. Define what you have to pass through JSON, string, int etc. Generate constructor and getter-setters for that. Your pojo class is complete.

Refer to the code below:

public class ExamplePojo {

    String id, first_name, last_name, email, password, mobile_no, parent_id, position, type, user, created_at, updated_at, deleted_at;
    int stage, total_child;


    public ExamplePojo(String id, String first_name, String last_name, String email, String password, String mobile_no, String parent_id, String position, String type, String user, String created_at, String updated_at, String deleted_at, int stage, int total_child) {
        this.id = id;
        this.first_name = first_name;
        this.last_name = last_name;
        this.email = email;
        this.password = password;
        this.mobile_no = mobile_no;
        this.parent_id = parent_id;
        this.position = position;
        this.type = type;
        this.user = user;
        this.created_at = created_at;
        this.updated_at = updated_at;
        this.deleted_at = deleted_at;
        this.stage = stage;
        this.total_child = total_child;
    }

    public String getId() {
        return id;
    }

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

    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 getEmail() {
        return email;
    }

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

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMobile_no() {
        return mobile_no;
    }

    public void setMobile_no(String mobile_no) {
        this.mobile_no = mobile_no;
    }

    public String getParent_id() {
        return parent_id;
    }

    public void setParent_id(String parent_id) {
        this.parent_id = parent_id;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getCreated_at() {
        return created_at;
    }

    public void setCreated_at(String created_at) {
        this.created_at = created_at;
    }

    public String getUpdated_at() {
        return updated_at;
    }

    public void setUpdated_at(String updated_at) {
        this.updated_at = updated_at;
    }

    public String getDeleted_at() {
        return deleted_at;
    }

    public void setDeleted_at(String deleted_at) {
        this.deleted_at = deleted_at;
    }

    public int getStage() {
        return stage;
    }

    public void setStage(int stage) {
        this.stage = stage;
    }

    public int getTotal_child() {
        return total_child;
    }

    public void setTotal_child(int total_child) {
        this.total_child = total_child;
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Abhilash Harsole
  • 244
  • 2
  • 4
  • 15