报错原因:你放的是一个非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. Java并发--ReentrantLock原理详解

    ReentrantLock是什么? ReentrantLock重入锁,递归无阻塞的同步机制,实现了Lock接口: 能够对共享资源重复加锁,即当前线程获取该锁,再次获取不会被阻塞: 支持公平锁和非公平锁 ...

  2. 小师妹学JVM之:JDK14中JVM的性能优化

    目录 简介 String压缩 分层编译(Tiered Compilation) Code Cache分层 新的JIT编译器Graal 前置编译 压缩对象指针 Zero-Based 压缩指针 Escap ...

  3. SpringBoot + Mybatis + Redis 整合入门项目

    这篇文章我决定一改以往的风格,以幽默风趣的故事博文来介绍如何整合 SpringBoot.Mybatis.Redis. 很久很久以前,森林里有一只可爱的小青蛙,他迈着沉重的步伐走向了找工作的道路,结果发 ...

  4. C# 9.0 新特性之只读属性和记录

    阅读本文大概需要 2 分钟. 大家好,这是 C# 9.0 新特性系列的第 4 篇文章. 熟悉函数式编程的童鞋一定对"只读"这个词不陌生.为了保证代码块自身的"纯洁&quo ...

  5. 尚硅谷 dubbo学习视频

    1 1.搭建zookpeer注册中心 windows下载zooker  需要修改下zoo_sample .cfg为zoo.cnf 然后需要zoo.cnf中数据文件的路径 第五步:把zoo_sample ...

  6. jni 字符串的梳理

    1.实现的功能是java层传递一个字符串到c层2.c层首先将jstring类型转换成char*类型3.c层对字符串进行处理之后,将处理之后的char*类型转换成jstring类型返回给上层的 pack ...

  7. android中使用https是否对服务证书合法性校验的新的体会

    package com.cetcs.logreport.utils; import android.content.Context; import org.apache.http.conn.ssl.S ...

  8. Python3-hashlib模块-加密算法之安全哈希

    Python3中的hashlib模块提供了多个不同的安全哈希算法的通用接口 hashlib模块代替了Python2中的md5和sham模块,使用这个模块一般分为3步 1.创建一个哈希对象,使用哈希算法 ...

  9. 【SpringMVC】

    前言

  10. Java项目开启远程调试(tomcat、springboot)

    当我们运行一个项目的时候,一般都是在本地进行debug.但是如果是一个分布式的微服务,这时候我们选择远程debug是我们开发的利器. 环境apache-tomcat-8.5.16 Linux 如何启用 ...