返回数据解析错误

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<Student> list = new ArrayList<Student>();
Type listType = new TypeToken<List<Student>>() {}.getType();
list = gson.fromJson(result, listType);

参考自:

http://stackoverflow.com/questions/18709730/com-google-gson-jsonsyntaxexception-java-lang-illegalstateexception-expected-b?rq=1

http://stackoverflow.com/questions/21520390/javax-ejb-ejbexception-com-google-gson-jsonsyntaxexception-java-lang-illegalst?rq=1

Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path 解决办法的更多相关文章

  1. gson Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path

    返回数据解析错误 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT ...

  2. Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2

    原因是解析的时候多了,逗号,或是 \ 解决方法:一 revJson=revJson.replace("\\", "");//去掉'/' revJson=revJ ...

  3. android报错 Expected BEGIN_OBJECT but was STRING at line 1 column 39 path $

    我在使用retrofit和Gson配合时,出现了这个问题,疑惑中乱七八糟瞎搞了一个下午没有解决.期间怀疑Gson解析不能使用泛型(因为我的解析使用了泛型),后来又觉得可能是我的关键字正好是解析器的某个 ...

  4. Invalid escape sequence at line 1 column 29 path $[0].name

    编译报错:Invalid escape sequence at line 1 column 29 path $[0].name 解决:grade.properties 文件下 org.gradle.j ...

  5. IDEA里运行代码时出现Error:scalac: error while loading JUnit4, Scala signature JUnit4 has wrong version expected: 5.0 found: 4.1 in JUnit4.class错误的解决办法(图文详解)

    不多说,直接上干货!  问题详情 当出现这类错误时是由于版本不匹配造成的 Information:// : - Compilation completed with errors and warnin ...

  6. macOS Mojave 10.14 无法安装brew缺少Command Line Tools for Xcode的解决办法

    问题描述: 首先我的版本是 Xcode 10.1 如果按照以前的方法安装brew 复制 1 /usr/bin/ruby -e "$(curl -fsSL https://raw.github ...

  7. Warning: Using a password on the command line interface can be insecure.解决办法

    被一个小朋友问到,直接公布答案: If your MySQL client/server version is a 5.6.x a way to avoid the WARNING message a ...

  8. MySQL Warning: Using a password on the command line interface can be insecure.解决办法

    转自 http://www.cnblogs.com/sunss/p/6256706.html  被一个小朋友问到,直接公布答案: If your MySQL client/server version ...

  9. 报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17) equal symbol expected

    现象:写了如下一个jsp文件,导入需要用到的两个包: 运行结果报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17 ...

随机推荐

  1. 两个div叠加触发事件发生闪烁问题

    今天遇到一个问题,想实现一个功能: 当鼠标移到div1上的时候,会出现div2.出现时div2在div1的上面,div2在出现后发生闪烁的问题. 于是开始找问题根源,发现原来是因为当我们触发div1的 ...

  2. Create and Install Timer Job in MOSS 2007

    Excute Timerjob public class TriggerLoadCacheTimerJob : SPJobDefinition { string ExceptionFlag = str ...

  3. Java Js实现导出csv

    $.ajax({ type: 'GET', async: false, url: '../../api/screening/exportTable?seriesIndex=' + param.seri ...

  4. C#中timer类的用法

    C#中timer类的用法 关于C#中timer类  在C#里关于定时器类就有3个   1.定义在System.Windows.Forms里   2.定义在System.Threading.Timer类 ...

  5. PHP redis 批量操作

    参考网站 phpredis扩展 :https://github.com/phpredis/phpredis#pconnect-popen 命令参考:http://doc.redisfans.com   ...

  6. supervisor centos安装

    一.安装配置supervisor 1.安装python自动化工具    #yum install python-setuptools 2.#easy_install supervisor安装super ...

  7. AndroidTouch事件总结

    1.自定义的控件几乎都要用到触摸事件,不交互怎么响应,相关的事件处理函数由dispatchTouchEvent.onInterceptTouchEvent.onTouchEvent,处理这些事件的由v ...

  8. 50款强力jquey,js 插件推荐

    http://www.cnblogs.com/xiaoyao2011/category/327551.html

  9. 【图像处理】【SEED-VPM】2.接口

    —————————————————————————————————————————————————————————————— 对比 ①最好是HDMI: ②分量也是高清的范围,得是比点对点的HDMI低一 ...

  10. STEP模块——电子钟

    原理 显示时分秒(日期也可以加上),两个按键调节时间 原理图 代码 /*---------------------------------------------------------------- ...