{
"retObj": [
{
"id": "2",
"1": [ "中文中文", "20151218" ],
"2": [ "中文中文", "中文中文" ],
"3": [ "中文中文", "中文中文" ],
"4": [ "中文中文", "中文中文" ],
"detail": [
{
"1": [ "中文中文", "AC123456789" ],
"2": [ "中文中文", "中文中文" ],
"3": [ "中文中文", "99.00" ],
"4": [ "中文中文", "7" ]
},
{
"1": [ "中文中文", "AD123456789" ],
"2": [ "中文中文", "中文中文" ],
"3": [ "中文中文", "77.00" ],
"4": [ "中文中文, "0" ]
}
]
},
各位先進前輩們,想請益請教,接收到後端所傳遞的資料時遇到的問題:
Array層層包,包的小弟眼花撩亂
小弟利用Bean 把資料類型先分出如下
public class Bean{
private List<RetObj> retObj;
public List<RetObj> getRetObj() {
return retObj;
}
public void setRetObj(List<RetObj> retObj) {
this.retObj = retObj;
}
public static class RetObj {
private String id;
@SerializedName("1")
private String list1;
@SerializedName("2")
private String list2;
@SerializedName("3")
private String list3;
@SerializedName("4")
private String list4;
private List<detail[]> detail;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getList1() {
return list1;
}
public void setList1(String list1) {
this.list1 = list1;
}
public String getList2() {
return list2;
}
public void setList2(String list2) {
this.list2 = list2;
}
public String getList3() {
return list3;
}
public void setList3(String list3) {
this.list3 = list3;
}
public String getList4() {
return list4;
}
public void setList4(String list4) {
this.list4 = list4;
}
public List<MedicineDataBean.detail[]> getDetail() {
return detail;
}
public void setDetail(List<MedicineDataBean.detail[]> detail) {
this.detail = detail;
}
}
public static class detail {
@SerializedName("1")
private String detailList1;
@SerializedName("2")
private String detailList2;
@SerializedName("3")
private String detailList3;
@SerializedName("4")
private String detailList4;
public String getDetailList1() {
return detailList1;
}
public void setDetailList1(String detailList1) {
this.detailList1 = detailList1;
}
public String getDetailList2() {
return detailList2;
}
public void setDetailList2(String detailList2) {
this.detailList2 = detailList2;
}
public String getDetailList3() {
return detailList3;
}
public void setDetailList3(String detailList3) {
this.detailList3 = detailList3;
}
public String getDetailList4() {
return detailList4;
}
public void setDetailList4(String detailList4) {
this.detailList4 = detailList4;
}
}
}
在解析資料方面的語法,如下
Gson gson = new Gson();
Type listType = new TypeToken<Collection<Bean>>() {}.getType();
Bean bean = gson.fromJson(result, listType);
請各位前輩,指點指點,小弟哪裡有錯誤,或是可以往哪個方向去尋找答案。
感恩感謝<(_ _)>
我是看不太懂你想問什麼, 我用Gson都是無腦使用下面的工具產生程式碼, 頂多稍微改改名字而已, 可以參考看看
http://www.jsonschema2pojo.org/
也有線上驗證Json格式的網站
https://jsonformatter.curiousconcept.com/#