我有这个json来自api。
{ "Table ":[[ "0 ", "--Please Select-- ",0],
[ "L ", "APPLICANTS ",1],[ "N ", "CANDIDATES ",2],
[ "C ", "CLIENTS ",3],[ "M ", "MEMBERS ",4],
[ "S ", "STAFF ",5]],
"Table1 ":[[1, "BY EMAIL "],
[3, "BY PUSH "],
[2, "BY SMS "],
[4, "CheckIn "],
[5, "CheckOut "]],
"Table2 ":[[ "ADMIN ", "ADMIN "],
[ "CEO ", "CHIEF EXECUTIVE OFFICER "],
[ "DON ", "DIRECTOR OF NURSING "],
[ "FO ", "FINANCE OFFICER "],
[ "GM ", "GENERAL MANAGER "],
[ "MGR ", "MANAGER "],
[ "OFA ", "OFFICER ALLOCATIONS "],
[ "ORE ", "OFFICER RECRUITMENT "],
[ "OTH ", "OTHERS "],
[ "PO ", "PERSONAL ASSISTANT "],
[ "REC ", "RECEPTIONIST "],
[ "SO ", "SALES OFFICER "],
[ "SW ", "SOCIAL WORKER "],
[ "STAFF ", "STAFF "]],
"Table3 ":[],
"Table4 ":[[1, "CONTACT OUT "]],
"Table5 ":[[ "151504 ", "CONTACT MEMBER ", "LOGCONTMBR "],
[ "151503 ", "EXTERNAL LOG ", "EXTRLOGONL "],
[ "151501 ", "INTERNAL LOG ", "INTLOGONLY "],
[ "151502 ", "SALES LOG ", "SALELOGONL "]],
"Table6 ":[],
"Table7 ":[],
"Table8 ":[[1, "New Client Visit "],
[2, "Client Visit "]]}
这是我用来解析json的响应类。它是由jsontopojo插件生成的。
public class RecordDataModel{
@SerializedName("Table ")
@Expose
private List<List<String>> table = null;
@SerializedName("Table1 ")
@Expose
private List<List<Integer>> table1 = null;
@SerializedName("Table2 ")
@Expose
private List<List<String>> table2 = null;
@SerializedName("Table3 ")
@Expose
private List<Object> table3 = null;
@SerializedName("Table4 ")
@Expose
private List<List<Integer>> table4 = null;
@SerializedName("Table5 ")
@Expose
private List<List<String>> table5 = null;
@SerializedName("Table6 ")
@Expose
private List<Object> table6 = null;
@SerializedName("Table7 ")
@Expose
private List<Object> table7 = null;
@SerializedName("Table8 ")
@Expose
private List<List<Integer>> table8 = null;
public List<List<String>> getTable() {
return table;
}
public void setTable(List<List<String>> table) {
this.table = table;
}
public List<List<Integer>> getTable1() {
return table1;
}
public void setTable1(List<List<Integer>> table1) {
this.table1 = table1;
}
public List<List<String>> getTable2() {
return table2;
}
public void setTable2(List<List<String>> table2) {
this.table2 = table2;
}
public List<Object> getTable3() {
return table3;
}
public void setTable3(List<Object> table3) {
this.table3 = table3;
}
public List<List<Integer>> getTable4() {
return table4;
}
public void setTable4(List<List<Integer>> table4) {
this.table4 = table4;
}
public List<List<String>> getTable5() {
return table5;
}
public void setTable5(List<List<String>> table5) {
this.table5 = table5;
}
public List<Object> getTable6() {
return table6;
}
public void setTable6(List<Object> table6) {
this.table6 = table6;
}
public List<Object> getTable7() {
return table7;
}
public void setTable7(List<Object> table7) {
this.table7 = table7;
}
public List<List<Integer>> getTable8() {
return table8;
}
public void setTable8(List<List<Integer>> table8) {
this.table8 = table8;
}
}
这是我正在使用的gson代码。
RecordDataModel recordDataModel = new Gson().fromJson(reader,RecordDataModel.class);
System.out.println("size "+recordDataModel.getTable().get(0).get(0));
recordDataModel
抛出空指针异常,我知道格式有点突然但这就是我所拥有的,我必须解析它。
我可能在这里缺少什么?
答案 0 :(得分:0)
您的代码中存在解析错误,您需要将Pojo DAY N-1 HSD N-2 HSD N-6 HSD DIP STOCK LTR PURRCHASE LTR Total Ltr Testing Sales As Reading Sales As Dip Diff Ltr Rate Rs Amount Rs
2017-08-31 00:00:00.000 1885620.00 1139191.00 391788.00 70.00 6310.00 10000.00 16310.00 10.00 0 0 0 59.78 0
2017-09-01 00:00:00.000 1886247.00 1139460.00 391836.00 140.00 15319.00 0.00 15319.00 10.00 0 0 0 59.86 0
2017-09-02 00:00:00.000 1887258.00 1139601.00 391938.00 130.00 14062.00 0.00 14062.00 10.00 0 0 0 59.94 0
----------------------------
----------------------------
2017-09-29 00:00:00.000 1909720.00 1147850.00 397467.00 102.40 10473.00 0.00 10473.00 10.00 0 0 0 61.57 0
2017-09-30 00:00:00.000 1910934.00 1148180.00 397467.00 90.60 8932.00 6000.00 14932.00 10.00 0 0 0 61.65 0
值更改为Integer
错误强>
引起:com.google.gson.JsonSyntaxException: java.lang.NumberFormatException:对于输入字符串:&#34; BY EMAIL&#34;
另外,从String
.get(0)
System.out.println()
答案 1 :(得分:0)
将POJO替换为以下类
public class RecordDataModel {
@SerializedName("Table ")
@Expose
private List<List<String>> table = null;
@SerializedName("Table1 ")
@Expose
private List<List<String>> table1 = null;
@SerializedName("Table2 ")
@Expose
private List<List<String>> table2 = null;
@SerializedName("Table3 ")
@Expose
private List<String> table3 = null;
@SerializedName("Table4 ")
@Expose
private List<List<String>> table4 = null;
@SerializedName("Table5 ")
@Expose
private List<List<String>> table5 = null;
@SerializedName("Table6 ")
@Expose
private List<String> table6 = null;
@SerializedName("Table7 ")
@Expose
private List<String> table7 = null;
@SerializedName("Table8 ")
@Expose
private List<List<String>> table8 = null;
public List<List<String>> getTable() {
return table;
}
public void setTable(List<List<String>> table) {
this.table = table;
}
public List<List<String>> getTable1() {
return table1;
}
public void setTable1(List<List<String>> table1) {
this.table1 = table1;
}
public List<List<String>> getTable2() {
return table2;
}
public void setTable2(List<List<String>> table2) {
this.table2 = table2;
}
public List<String> getTable3() {
return table3;
}
public void setTable3(List<String> table3) {
this.table3 = table3;
}
public List<List<String>> getTable4() {
return table4;
}
public void setTable4(List<List<String>> table4) {
this.table4 = table4;
}
public List<List<String>> getTable5() {
return table5;
}
public void setTable5(List<List<String>> table5) {
this.table5 = table5;
}
public List<String> getTable6() {
return table6;
}
public void setTable6(List<String> table6) {
this.table6 = table6;
}
public List<String> getTable7() {
return table7;
}
public void setTable7(List<String> table7) {
this.table7 = table7;
}
public List<List<String>> getTable8() {
return table8;
}
public void setTable8(List<List<String>> table8) {
this.table8 = table8;
}}