com.alibaba.fastjson.JSONException: syntax error, expect {, actual [, pos 0

简介:         在使用fastjson解析的时候遇到该错误,网上查找了半天,找到位大神的帖子是说解析的实体A中有实体B,在该条json中A实体只有一个,但B实体却有多个,导致解析出错,解决办法是在A实体中定义B实体时,定义为List,这个是大神当时遇到的错误。

        在使用fastjson解析的时候遇到该错误,网上查找了半天,找到位大神的帖子是说解析的实体A中有实体B,在该条json中A实体只有一个,但B实体却有多个,导致解析出错,解决办法是在A实体中定义B实体时,定义为List<B>,这个是大神当时遇到的错误。我的错误不在于此。

我的错误是由于在封装json时封装的实体时List类型的,但解析的时候默认解析为一个实体,所以就出现了以上的错误

解析时的代码Moyiol_order mOrder=JSON.parseObject(ordersinfo, Moyiol_order.class);

封装时的代码List<Moyiol_order> result;

JSON.toJSONString(result);

只要在封装的时候将result取出要用的实体封装就可以了,如果需要封装多个实体,可以借鉴大神的思想自己寻找一下方法。

http://blog.csdn.net/jadyer/article/details/24395015

目录
相关文章
|
1月前
|
SQL Java 数据库连接
【问题解决】nested exception is org.apache.ibatis.exceptions.TooManyResultException:Expected one result
【问题解决】nested exception is org.apache.ibatis.exceptions.TooManyResultException:Expected one result
|
4月前
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘order‘. Caus
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘order‘. Caus
32 0
|
3天前
|
索引
Elasticsearch exception [type=illegal_argument_exception, reason=index [.1] is the write index for data stream [slowlog] and cannot be deleted]
在 Elasticsearch 中,你尝试删除的索引是一个数据流(data stream)的一部分,而且是数据流的写入索引(write index),因此无法直接删除它。为了解决这个问题,你可以按照以下步骤进行操作:
|
18天前
|
Java
org.apache.jasper.JasperException...(line: 15, column: 16) quote symbol expected和处理办法
org.apache.jasper.JasperException...(line: 15, column: 16) quote symbol expected和处理办法
|
数据库
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
604 0
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
|
8月前
|
存储 应用服务中间件
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template
Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found
Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found
91 0
|
Java Apache
Cause: the class org.apache.tools.ant.taskdefs.optional.ANTLR was not found.
Cause: the class org.apache.tools.ant.taskdefs.optional.ANTLR was not found.
84 0
Dx unsupported class file version 52.0 Conversion to Dalvik format failed with error 1
Dx unsupported class file version 52.0 Conversion to Dalvik format failed with error 1
117 0
|
JSON 数据格式
报错:应用json.parseObject()方法时JSONException: syntax error, expect {, actual [, pos 0
报错:应用json.parseObject()方法时JSONException: syntax error, expect {, actual [, pos 0
731 0