返回数据解析错误

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的更多相关文章

  1. 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. 报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17) equal symbol expected

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

  6. 异常-----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 ...

  7. 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的时候,遇到这个问题,百度之后,看到大家的解决方案 ...

  8. 报错:严重: 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 [ ...

  9. 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 ...

随机推荐

  1. python BeautifulSoup

    之前解析LXML,用的是XPath,现在临时被抓取写爬虫,接人家的代码,看到用的是BeautifulSoup,稍微学了下,也挺好用的,简单记录下用法,有机会做下和Xpath的对比测试 初始化 from ...

  2. Spark记录-实例和运行在Yarn

    #运行实例 #./bin/run-example SparkPi 10   #./bin/spark-shell --master local[2] #./bin/pyspark --master l ...

  3. [iOS]@synthesize和@dynamic关键字

    首先讲@property, 这是iOS6以后出来的关键词. 用它声明一个属性之后, 编译器会自动给你生成setter和getter方法的声明以及实现还有一个以_xxx 的成员变量(xxx是你属性定义的 ...

  4. javascript设计模式开篇:Javascript 接口的实现

    javascript语言不像java. c#. c++等面向对象语言那样有完备的接口支持,在javascript中,接口的实现有三种方式,分别为注释描述.属性检查.鸭式变形.注释描述实现起来最为简单, ...

  5. 如何使用 grunt

    1>. 首先要有nodejs环境, 至少0.8.0版本: 2>. 转到 项目文件夹下: >npm install –g grunt-cli >npm init #生成一个基本的 ...

  6. 新建 Spring Mvc Web + Maven 的 maven 错误 (二)

    新建项目后,可能由于哪边配置不正确,或也可能是编码问题,就有可能在创建初始就可能发生错误: 这是 pom.xml 中提示的错误,有的人说要删除 maven 的本地仓库位置:c:\用户[Users]\A ...

  7. mongoDB - 日常操作四

    python 使用 mongodb easy_install pymongo # 安装(python2.+) import pymongo connection=pymongo.Connection( ...

  8. Linux环境下FTP工具的使用方法

    在Windows环境下创建Ftp目录作为服务器根目录 在Linux端的操作: 从服务器端下载文件到Linux端: ftpget -u User -p Password ServerIP File Fi ...

  9. fuzz for test of the Net::HTTP::GET

    use Net::HTTP::GET; % %0e%0f ' *%26 @.jpg>; my $count = 0; for @chars X @chars X @chars X @chars ...

  10. 恶意代码分析实战-确认EXE什么时候编译的

    场景 确认开源的后门在中毒机器上是什么版本,具有什么功能. 思路 1.查看样本PE里的编译时间 2.对照开源后门里组件的编译时间 技术点 查看NT头-TimeDateStamp struct IMAG ...