com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was B

今天用GSON解析数据时出现如下错误:

Android Studio:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

现找到如下解决办法:

链接:

http://www.oschina.net/question/1248547_121737

方法:

如果返回的是数组

这么解析

List depts = gson.fromJson(gsonString, new TypeToken>(){}.getType());  

如果返回的是数据bean这么解析即可

Dept depts = gson.fromJson(gsonString, Dept.class);


你可能感兴趣的:(#,android,Bug处理)