Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path

阅读更多
返回数据解析错误

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

期望返回一个对象但是却返回了一个数组

解决办法:
1.在参数中修改期望返回类 Student 为 LIst< Student>,这样才能解析到数据。

2.用 TypeToken 转一下:

Gson gson = new Gson();
String result = response;

ArrayList list = new ArrayList();
Type listType = new TypeToken>() {}.getType();
list = gson.fromJson(result, listType);

你可能感兴趣的:(gson)