报错原因:你放的是一个非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的更多相关文章

  1. 【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 ...

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

  3. redis通过json方案存取对象com.alibaba.fastjson.JSONException: syntax error, expect

    问题描述: redis基于json方案存取对象时报错:com.alibaba.fastjson.JSONException: syntax error, expect com.alibaba.fast ...

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

  5. 做文件上传下载时报这个错com.alibaba.fastjson.JSONException: illegal identifier : \

    ::-exec-] DEBUG c.i.e.m.I.insertDataEmebeding - <== Updates: ::-exec-] ERROR c.i.e.c.CaseArchiveC ...

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

  7. fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string: "13:02:19"

    问题:time类型数据插入不进mysql数据库:调试的时候报如下错误: Caused by: java.lang.NumberFormatException: For input string: &q ...

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

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

随机推荐

  1. 01 . MongoDB简介及部署配置

    简介 什么是MongoDB? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在为WEB应用 ...

  2. ASP.NET WebAPI框架解析第二篇(HttpModule的创建和使用)

    我们先看一下执行流程图 图中画红圈的部分便是HttpModule,在说创建HttpModule之前,先说一下HttpApplication对象,HttpApplication对象由Asp.net框架创 ...

  3. 查找nginx安装目录并启动

    今天公司突然停电,来电后发现服务无法访问了,服务器是部署在公司内 发现ip ping 不通,是服务器没开 手动开了服务器,还是无法访问 可以FTP,但是不能访问服务,说明机器已经开了,有些东西应该没启 ...

  4. JavaWeb网上图书商城完整项目--过滤器解决中文乱码

    我们知道,如果是POST请求,我们需要调用request.setCharacterEncoding(“utf-8”)方法来设计编码:如果是GET请求,我们需要自己手动来处理编码问题.如果我们使用了En ...

  5. activity的四种启动模式详细分析

    1.android中通过任务队列来管理activity 采用栈的结构就是后进先出 手机里面如果启动多个应用就会启动多个任务栈来管理对应的activity. 主要解决下面的问题:对应的四种启动模式: 1 ...

  6. springboot_自动配置原理

    目录 1.1 @SpringBootApplication 2.1 @EnableAutoConfiguration 2.1.1 @AutoConfigurationPackage 2.1.2 @Im ...

  7. hive中left semi join 与join 的区别

    LEFT SEMI JOIN:左半开连接会返回左边表的记录,前提是其记录对于右边表满足ON语句中的判定条件.对于常见的内连接(INNER JOIN),这是一个特殊的,优化了的情况.大多数的SQL方言会 ...

  8. java语言进阶(六)_线程_同步

    第一章 多线程 想要设计一个程序,边打游戏边听歌,怎么设计? 要解决上述问题,需要使用多进程或者多线程来解决. 1.1 并发与并行 并发:指两个或多个事件在同一个时间段内发生. 并行:指两个或多个事件 ...

  9. 如何利用.NETCore向Azure EventHubs准实时批量发送数据?

    最近在做一个基于Azure云的物联网分析项目: .netcore采集程序向Azure事件中心(EventHubs)发送数据,通过Azure EventHubs Capture转储到Azure Blog ...

  10. 痞子衡嵌入式:轻松为i.MXRT设计更新Segger J-Link Flash下载算法文件

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是为i.MXRT设计更新Segger J-Link Flash下载算法文件. 想要在Flash中调试,基本是离不开Flash下载算法的,毕 ...