我有这个 JSON
{"A":"valA",
"B":["valB"],
"C":"valC",
"D":"valD",
"data":[{
"data1":"dval1",
"data2":"dval2",
"data3":"dval3",
"data4":"dval4",}],
"F":"valF"}
Java 对象:
public class ABCDObject {
private String A;
private String B;
private String C;
private String D;
private List<String> data = new ArrayList<String>(){
{
add("data1");
add("data2");
add("data3");
add("data4");
}
};
private String F;
//getters for the above A,B,C,D, and F
public List<String> getData() {
return data;
}
主班
Gson gson = new Gson();
ABCDObject abcdObj = gson.fromJson(response, ABCDObject.class);
我正在尝试访问 C 的值
abcdObj.getC();
我收到错误 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 9 column 17
另一个问题是如何访问data的值-->data1等等