0
如何使用谷歌的GSON複雜的JSON轉換爲Java對象複雜的JSON到Java對象轉換和我的JSON是一些這樣的事:如何使用GSON
{
"error": "200",
"status": "OK",
"BarList": {
"Bar1": {
"Name": "yash",
"sex": "male",
"Type": "barowner",
"userId": "x25df",
"ContactNo": "1234567890",
"zipCode": "110055",
"Address": "Ghumtarastachaltigali",
"Email": "[email protected]"
},
"Bar2": {
"Name": "yash",
"sex": "male",
"Type": "barowner",
"userId": "x25df",
"ContactNo": "1234567890",
"zipCode": "110055",
"Address": "Ghumtarastachaltigali",
"Email": "[email protected]"
}
}
}
對於這個JSON映射到我的java對象我取得了3類 第一:BarListResponse - 在我這樣做: -
public class BarListResponse {
@SerializedName("error")
@Expose(serialize = false)
String errrocode;
@Expose(serialize = false)
String status;
@SerializedName("data")
Bar bar_list[];
public String getErrrocode() {
return errrocode;
}
public void setErrrocode(String errrocode) {
this.errrocode = errrocode;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Bar[] getLst() {
return bar_list;
}
public void setLst(Bar lst[]) {
this.bar_list = lst;
}
}
第二欄列表:
public class BarList {
@SerializedName("Bar")
Bar bar[];
public Bar[] getBar() {
return bar;
}
public void setBar1(Bar bar[]) {
this.bar = bar;
}
}
;第三是
public class Bar {
String Name;
String sex;
String type;
String userId;
double ContactNo;
double zipCode;
String Address;
String Email;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public double getContactNo() {
return ContactNo;
}
public void setContactNo(double contactNo) {
ContactNo = contactNo;
}
public double getZipCode() {
return zipCode;
}
public void setZipCode(double zipCode) {
this.zipCode = zipCode;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
}
從這個我想通過一個獲取各條之一的細節。
請幫忙解決這個問題。 在此先感謝。
它被命名爲BarList而不是數據。 @SerializedName(「data」) Bar bar_list []; – 2014-10-04 13:35:16
你試過新的Gson()。fromJson(userinput,BarList.class); – 2018-02-08 15:41:21