我的JSON
如下,
[{
"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
}
}]
答案 0 :(得分:0)
使用Gson lib中的SerializedName:
public class myPojo{
@SerializedName("0")
private String one;
@SerializedName("1")
private String two;
.....
}
答案 1 :(得分:0)
创建一个Java类。定义你必须通过JSON,string,int等传递的内容。为此生成构造函数和getter-setter。你的pojo课程已经完成。
请参阅以下代码:
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;
}
}