gson 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<Student> list = new ArrayList<Student>();
Type listType = new TypeToken<List<Student>>() {}.getType();
list = gson.fromJson(result, listType);
=====
原因是数据的前后多了[ ]中括号。
String gsonStr1= "[{name:'name0',age:0}]";
解决办法:
将前后的中括号去掉就好了。
//修改后{name:'name0',age:0},要去掉前后的括号。
String gsonStr1= "{name:'name0',age:0}";
=======
gson Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path的更多相关文章
- Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path 解决办法
返回数据解析错误 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT ...
- Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
原因是解析的时候多了,逗号,或是 \ 解决方法:一 revJson=revJson.replace("\\", "");//去掉'/' revJson=revJ ...
- android报错 Expected BEGIN_OBJECT but was STRING at line 1 column 39 path $
我在使用retrofit和Gson配合时,出现了这个问题,疑惑中乱七八糟瞎搞了一个下午没有解决.期间怀疑Gson解析不能使用泛型(因为我的解析使用了泛型),后来又觉得可能是我的关键字正好是解析器的某个 ...
- 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 ...
- 报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17) equal symbol expected
现象:写了如下一个jsp文件,导入需要用到的两个包: 运行结果报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17 ...
- 异常-----freemarker.template.TemplateException: Expected collection or sequence. datas evaluated instead to freemarker.core.HashLiteral$SequenceHash on line 7, column 18 in inc/select.ftl.
1.错误描述 六月 26, 2014 11:26:27 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...
- Exception in thread "main" expected '<document start>', but found BlockMappingStart in 'reader', line 23, column 2: nimbus.host: "master"
平台:centos-6.3-i386 jdk-7u51 storm 0.9.1 python 2.6.6 hadoop 1.2.1 启动storm的时候,遇到这个问题,百度之后,看到大家的解决方案 ...
- 报错:严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [/index.jsp (line: 13, column: 20) No tag "textfiled" defined in tag library imported with prefix
严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [ ...
- ORA-06550:line 1,column 7;PLS-00201:indentifer '存储过程' must be declared;...PL/SQL Statement ignored 问题
前段时间由于修改SMES系统,出现了一个问题. ORA-06550:line 1,column 7;PLS-00201:indentifer '存储过程' must be declared;...PL ...
随机推荐
- 支付宝APP支付,提示代码 ALIN10070
ALIN10070 此代码时ALI64代码拆分后的细分代码: 代表签名验证失败等相关问题: 如果近期修改过或者续签 过签约协议,也需要更新公私钥.
- tweenMax学习笔记
tweenMax是一款缓动插件,能实现很多牛逼的效果,在网上看了些demo,确实很吊,虽说很多用CSS3也能做出来,但是技多不压身,学之. 网上的demo还是很多的,但是资料不多,唯一能够让我有思绪的 ...
- nodejs图片总结
今天终于把朴灵老师写的<深入浅出Node.js>给学习完了, 这本书不是一本简单的Node入门书籍,它没有停留在Node介绍或者框架.库的使用层面上,而是从不同的视角来揭示Node自己内在 ...
- element-UI 下拉条数多渲染慢
本文地址:https://www.cnblogs.com/veinyin/p/10120398.html 如果渲染为普通下拉框,用户难以找到要选择的那一项,增加模糊搜索功能,可解决渲染缓慢问题,但用户 ...
- Javascript - Vue - 过滤器
过滤器 输出的数据由vue对象提供,但它的数据可能需要做进一步的处理才适合展示给用户看,为此,可以在静态的Vue上定义一个过滤器对实例vue对象的data数据进行过滤处理. //调用过滤器//msg是 ...
- Plus One & Plus One Linked List
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- JavaScript中对象与函数的某些事[JavaScript语言精粹-N1]
今天在读<JavaScript语言精粹>的时候,关于函数的一个部分,始终觉得有点难以理解,代码如下: 1: var obj = (function(){ 2: var value = 0; ...
- SPListItem.UpdateOverwriteVersion()真的不会创建新版本吗?
根据msdn文档, SPListItem.UpdateOverwriteVersion(): Updates the item without creating another version of ...
- 数据库索引和SQL语句使用经验
1.如果检索数据量超过30%的表中记录数,使用索引将没有显著的效率提高 2.在特定情况下,使用索引也许会比全表扫描慢,但这是同一个数量级上的差距:而通常情况下,使用索引比全表扫描要快几倍乃至几千倍! ...
- springboot整合Thymeleaf模板引擎
引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...