Android gson.fromjson返回null
这个json来自apiAndroid gson.fromjson返回null,android,json,gson,Android,Json,Gson,这个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 "],
{ "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;
}
}
recordDataModel
抛出空指针异常,我知道格式有点突然,但这就是我所拥有的,我必须解析它
这里可能缺少什么?代码中存在解析错误,您需要将Pojo
Integer
值更改为String
错误
原因:com.google.gson.JsonSyntaxException:
java.lang.NumberFormatException:对于输入字符串:“通过电子邮件”
另外,从System.out.println()中删除一个.get(0)
公共类RecordDataModel{
@序列化名称(“表”)
@暴露
私有列表表=null;
@序列化名称(“表1”)
@暴露
私有列表table1=null;
@序列化名称(“表2”)
@暴露
私有列表table2=null;
@序列化名称(“表3”)
@暴露
私有列表table3=null;
@序列化名称(“表4”)
@暴露
私有列表table4=null;
@序列化名称(“表5”)
@暴露
私有列表表5=null;
@序列化名称(“表6”)
@暴露
私有列表table6=null;
@序列化名称(“表7”)
@暴露
私有列表table7=null;
@序列化名称(“表8”)
@暴露
私有列表table8=null;
公共列表getTable(){
返回表;
}
公共void可设置(列表表){
this.table=表格;
}
公共列表getTable1(){
返回表1;
}
公共无效设置表1(列表表1){
表1=表1;
}
公共列表getTable2(){
返回表2;
}
公共无效设置表2(列表表2){
表2=表2;
}
公共列表getTable3(){
返回表3;
}
公共无效设置表3(列表表3){
表3=表3;
}
公共列表getTable4(){
返回表4;
}
公共无效设置表4(列表表4){
表4=表4;
}
公共列表getTable5(){
返回表5;
}
公共无效设置表5(列表表5){
表5=表5;
}
公共列表getTable6(){
返回表6;
}
公共无效设置表6(列表表6){
表6=表6;
}
公共列表getTable7(){
返回表7;
}
公共无效设置表7(列表表7){
表7=表7;
}
公共列表getTable8(){
返回表8;
}
公共无效设置表8(列表表8){
表8=表8;
}
}
将您的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;
}}
公共类RecordDataModel{
@序列化名称(“表”)
@暴露
私有列表表=null;
@序列化名称(“表1”)
@暴露
私有列表table1=null;
@序列化名称(“表2”)
@暴露
私有列表table2=null;
@序列化名称(“表3”)
@暴露
私有列表table3=null;
@序列化名称(“表4”)
@暴露
私有列表table4=null;
@序列化名称(“表5”)
@暴露
私有列表表5=null;
@序列化名称(“表6”)
@暴露
私有列表table6=null;
@序列化名称(“表7”)
@暴露
私有列表table7=null;
@序列化名称(“表8”)
@暴露
私有列表table8=null;
公共列表getTable(){
返回表;
}
公共void可设置(列表表){
this.table=表格;
}
公共列表getTable1(){
返回表1;
}
公共无效设置表1(列表表1){
表1=表1;
}
公共列表getTable2(){
返回表2;
}
公共无效设置表2(列表表2){
表2=表2;
}
公共列表getTable3(){
返回表3;
}
公共无效设置表3(列表表3){
表3=表3;
}
公共列表getTable4(){
返回表4;
}
公共无效设置表4(列表表4){
表4=表4;
}
公共列表getTable5(){
返回表5;
}
公共无效设置表5(列表表5){
表5=表5;
}
公共列表getTable6(){
返回表6;
}
公共无效设置表6(列表表6){
表6=表6;
}
公共列表getTable7(){
返回表7;
}
公共无效设置表7(列表表7){
表7=表7;
}
公共列表getTable8(){
返回表8;
}
公共无效设置表8(列表表8){
表8=表8;
}}
解析第一个表时可能会出现错误1,您指定了一个整数列表,但我们可以在json上看到情况并非如此,您有整数和strings@Carnal是的,可能是,在这种情况下该怎么办?将错误日志和问题一起发布。@akhilesh0707没有gson的错误日志,当我试图打印列表的大小时,“recordDataModel”对象出现空指针异常。@SachinMalik能否尝试从sop中删除一个。get(0)
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<Object> 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<Object> table6 = null;
@SerializedName("Table7 ")
@Expose
private List<Object> 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<Object> getTable3() {
return table3;
}
public void setTable3(List<Object> 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<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<String>> getTable8() {
return table8;
}
public void setTable8(List<List<String>> table8) {
this.table8 = table8;
}
}
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;
}}