Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 colu

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2

 

原因:

数据的前后多了[ ]中括号。

String gsonStr1= "[{name:'name0',age:0}]";

解决办法1:

将前后的中括号去掉就好了。

//修改后{name:'name0',age:0},要去掉前后的括号。
String gsonStr1= "{name:'name0',age:0}";

 

解决方案2:

Type listType = new TypeToken>() {}.getType();

ArrayList electronicFenceBean = new Gson().fromJson(str, listType);

你可能感兴趣的:(Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 colu)