com.aliyun.openservices.shade.com.alibaba.fastjson.JSONException: exepct '[', but {, pos 1, line 1, column 2
报错原因:你放的是一个非List的对象 却想取一个List对象出来
package test; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; public class VarTest { public static void main(String[] args) { LiuJieTestObj obj = new LiuJieTestObj();
obj.setId(111L);
Date date1 = new Date(2019, 7, 23);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.format(date1);
obj.setTestDate(date1);
// 错误示范1 报错:Exception in thread "main" com.alibaba.fastjson.JSONException: expect '[', but {, pos 1, line1,column 2
String str1 = JSON.toJSONString(obj);// 放进去的不是List
System.out.println("str1:"+str1);//str1:{"id":111,"testDate":61524633600000}
List<LiuJieTestObj> objList1 = JSON.parseArray(str1, LiuJieTestObj.class);// 取一个List // 错误示范2 报错:Exception in thread "main" com.alibaba.fastjson.JSONException: expect '[', but {, pos 1, line1,column 2
String str2 = JSONArray.toJSONString(obj);// 放进去的是非List的对象
System.out.println("str2:"+str2);//str2:{"id":111,"testDate":61524633600000}
List<LiuJieTestObj> objList2 = JSON.parseArray(str2, LiuJieTestObj.class);// 取一个List // 正确示范3
List<LiuJieTestObj> list = new ArrayList<>();
list.add(obj);
String str3 = JSON.toJSONString(list);// 放进去的是List
System.out.println("str3:"+str3);//str3:[{"id":111,"testDate":61524633600000}]
List<LiuJieTestObj> objList3 = JSON.parseArray(str3, LiuJieTestObj.class);// 取一个List }
}
package test; import java.util.Date; public class LiuJieTestObj {
private Long id ;
private Date testDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getTestDate() {
return testDate;
}
public void setTestDate(Date testDate) {
this.testDate = testDate;
}
}
com.aliyun.openservices.shade.com.alibaba.fastjson.JSONException: exepct '[', but {, pos 1, line 1, column 2的更多相关文章
- 【RocketMQ异常】Caused by: com.aliyun.openservices.shade.com.alibaba.rocketmq.client.exception.MQClientException: No route info of this topic, message-service-topic-testf
一.异常信息 -- ::-thread-] ERROR c.x.x.r.service.producer.ali.AliMQProducerProcess.sendMessageFromQueue(A ...
- com.alibaba.fastjson.JSONException: exepct '[', but error, pos 1, json : %255B%257B%2522list%2522%253A%255B%257B%2522itemId%2522%253A1369331%252C%2522num%2522%253A2%257D%255D%257D%255
com.alibaba.fastjson.JSONException: exepct '[', but error, pos 1, json : %255B%257B%2522list%2522%25 ...
- redis通过json方案存取对象com.alibaba.fastjson.JSONException: syntax error, expect
问题描述: redis基于json方案存取对象时报错:com.alibaba.fastjson.JSONException: syntax error, expect com.alibaba.fast ...
- com.alibaba.fastjson.JSONException: default constructor not found. class ……
1.json工具类 package com.hyzn.fw.util; import java.util.List; import java.util.Map; import com.alibaba. ...
- 做文件上传下载时报这个错com.alibaba.fastjson.JSONException: illegal identifier : \
::-exec-] DEBUG c.i.e.m.I.insertDataEmebeding - <== Updates: ::-exec-] ERROR c.i.e.c.CaseArchiveC ...
- com.alibaba.fastjson.JSONException: For input string: "8200-12-31"
https://www.cnblogs.com/mengjinluohua/p/5544987.html https://samebug.io/exceptions/458113/com.alibab ...
- fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string: "13:02:19"
问题:time类型数据插入不进mysql数据库:调试的时候报如下错误: Caused by: java.lang.NumberFormatException: For input string: &q ...
- JSON parse error: default constructor not found. class java.time.YearMonth; nested exception is com.alibaba.fastjson.JSONException: default constructor not found. class java.time.YearMonth
java8新出的YearMonth可以方便的用来表示某个月.我的项目中使用springmvc来接收YearMonth类型的数据时发现 x-www-from-urlencoded 格式的数据可以使用&q ...
- Caused by: com.alibaba.fastjson.JSONException: syntax error, expect {, actual [, pos 0, fastjson-version 1.2
环境: vue.js 问题: 当添加评论时 重新查询数据刷新数据控制台异常Caused by: com.alibaba.fastjson.JSONException: syntax error, ex ...
随机推荐
- 密码学数论基础部分总结之 有限域GF(p) Galois Fields
今天花了一下午的时间学习密码学的数论部分,下面将学到的内容进行一下总结,也算是加深记忆.我本身对密码学这方面比较感兴趣,而且本节出现了许多数学公式,使用刚刚学习的LaTex公式来呈现出来,练习练习,何 ...
- 【JMeter_15】JMeter逻辑控制器__仅一次控制器<Once Only Controller>
仅一次控制器<Once Only Controller> 业务逻辑: 在每个线程内,该控制器下的内容只会被执行一遍,无论循环多少次,都只执行一遍.<嵌套在循环控制器之内时是个例外,每 ...
- vc6.0代码转vs2017相关问题
vc6.0代码转vs2017相关问题 命令行 error D8016: “/ZI”和“/Gy-”命令行选项不兼容fatal error C1083: 无法打开包括文件: “WinSock2.h”: N ...
- 微信小程序入门基础
微信小程序入门基础 视频教程(https://edu.csdn.net/course/detail/8456?pre_view=1) 第一章.认识小程序 1.工具的下载与安装 2.小程序代码构成 ...
- Spring Boot 系列
https://www.cnblogs.com/magicalSam/p/7189421.html
- 动力节点 mysql 郭鑫 34道经典的面试题
DROP TABLE IF EXISTS `dept`; CREATE TABLE `dept` ( `DEPTNO` int(2) NOT NULL COMMENT '部门编号', `DNAME` ...
- Day10-微信小程序实战-交友小程序-创建friendList字段实现好友关系(添加好友功能)--内附代码
回顾:之前我们进行了删除的功能,以及对message消息的增删,下面实现添加好友的功能 我们先在数据库中,在message这个字段的list里面,添加上测试号的id,就是模拟这个两个测试号要加我主号的 ...
- 硬件对同步的支持-TAS和CAS指令
目录 Test and Set Compare and Swap 使用CAS实现线程安全的数据结构. 现在主流的多处理器架构都在硬件水平上提供了对并发同步的支持. 今天我们讨论两个很重要的硬件同步指令 ...
- 暑假集训Day2 状压dp 特殊方格棋盘
首先声明 : 这是个很easy的题 可这和我会做有什么关系 题目大意: 在n*n的方格棋盘上放置n个车,某些格子不能放,求使它们不能互相攻击的方案总数. 注意:同一行或同一列只能有一个车,否则会相互攻 ...
- 并发05--JAVA并发容器、框架、原子操作类
一.ConcurrentHashMap的实现原理与使用 1.为什么要使用ConsurrentHashMap 两个原因,hashMap线程不安全(多线程并发put时,可能造成Entry链表变成环形数据结 ...