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

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/79944897

今天用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<Dept> depts = gson.fromJson(gsonString, new TypeToken<List<Dept>>(){}.getType());  

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

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


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页