我遇到了关于GSON json到Java的问题。我在这里查了很多帖子,但是找不到我的问题的解决方案。所以我在这里列出我的问题。非常感谢!
这是我的Json数据
"{
"data": {
"marks": "",
"spines": "",
"dendrites": {
"voxel": [
[383,382,382,381],
[49,50,51,52],
[7,10,10,10],
[0,0,0,0]
],
"maxint": [32,42,28,28],
"maxintcorrected": null,
"maxintcube": null,
"medianfiltered": [54.36979745,54.36979745,54.36979745,54.36979745],
"meanbacksingle": null,
"maxintsingle": null,
"thres": null,
"meanback": 42,
"index": 1,
"length": [0,0.3223757885,0.6336712814,0.9350672197,1.227262867],
"XYlength": [0,0.2085982964,0.410997367,0.6084466603]
}
}
}
"
我的班级的定义如下:
public class Test {
public data data;
public class data {
public Object marks;
public String spines = "";
public StandardSpinenalysisImage.data.dendrites[] dendrites;
public class dendrites {
public int voxel[][];
public int maxint[];
public String maxintcorrected = "";
public String maxintcube = "";
public int medianfiltered[];
public String meanbacksingle = "";
public String maxintsingle = "";
public int thres = 0;
public int meanback;
public int index = 0;
public int length[];
public int XYlength[];
public dendrites() {
this.thres = 100;
}
}
}
}
但是当我使用代码时 测试t = g.fromJson(输入,Test.class);
我收到了错误结果。
Exception in thread "AWT-EventQueue-0" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 5
非常感谢你!
答案 0 :(得分:2)
您可以尝试使用this link来验证您的json
答案 1 :(得分:1)
今天面临同样的错误。在我的问题中,问题是JSON中的一个变量映射到String,但在类中,变量位于Class Type的对象上。这使得Gson认为JSON变量应该是Class Type,导致带有Expected BEGIN_OBJECT but was STRING
的IllegalStateException
希望它有所帮助。