错误提示“com.alibaba.fastjson.JSONException: exepct '[', but string, pos 4, json”解决
1、错误提示信息如下:
com.alibaba.fastjson.JSONException: exepct '[', but string, pos 4, json : "[{"attrId":33,"attrName":"粗跟"},{"attrId":44,"attrName":"厚底"}]"
at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:672)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:662)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:657)
at com.alibaba.fastjson.JSON.parseArray(JSON.java:514)
2、原始代码:
List<AttributeServiceImpl.AttrValue> attrValues = JSON.parseArray(
s, AttributeServiceImpl.AttrValue.class);
作用:就是把从数据库中取出来的json字符串解析成List对象。
3、问题分析:
1)网上有说使用: JSON.toJSON(s).toString() 转化一下,于是修改
JSON.parseArray(
JSON.toJSON(s).toString(), AttributeServiceImpl.AttrValue.class);
发现还是报错。
2)直接定义变量试一下:
String s="[{\"attrId\":33,\"attrName\":\"粗跟\"},{\"attrId\":44,\"attrName\":\"厚底\"}]"
JSON.parseArray(
JSON.toJSON(s).toString(), AttributeServiceImpl.AttrValue.class);
发现没有问题,可以运行,那就奇怪了。
3)于是仔细看数据库表中的数据:
终于发现问题,这个json字符串的前后,分别多了一个双引号

于是把前后双引号去掉之后,再进行解析,问题解决。
4、后记:
小问题不大,有时候并不能一眼看出来,很是苦恼 ,需要耐心的找原因,当问题解决之后,才恍然大悟。
错误提示“com.alibaba.fastjson.JSONException: exepct '[', but string, pos 4, json”解决的更多相关文章
- 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 ...
- fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string: "13:02:19"
问题:time类型数据插入不进mysql数据库:调试的时候报如下错误: Caused by: java.lang.NumberFormatException: For input string: &q ...
- 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. ...
- 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 ...
- redis通过json方案存取对象com.alibaba.fastjson.JSONException: syntax error, expect
问题描述: redis基于json方案存取对象时报错:com.alibaba.fastjson.JSONException: syntax error, expect com.alibaba.fast ...
- 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 ...
- 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 ...
- 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 ...
- 解决使用Redis时配置 fastjson反序列化报错 com.alibaba.fastjson.JSONException: autoType is not support
1.问题描述 在使用redis时,配置自定义序列化redisTemplate为FastJsonRedisSerializer . 1 /** 2 * 自定义redis序列化器 3 */ 4 @Sup ...
随机推荐
- UEditor采坑指南
1.版本选择 GitHub上的最新版(1.5)没有提供后端代码.想要后端代码可以下载历史版本(1.4.3.3). 1.5版本:https://github.com/fex-team/ueditor 1 ...
- 在windows系统下用vscode构造shell脚本IDE
1.基础环境搭建 安装Visual Studio Code(VScode ) 下载地址:https://code.visualstudio.com/Download 下载完双击文件,选择路径安装即可, ...
- 数据采集之刷cnblog评论
python代码如下: import random import time import requests cookies = { '__gads': 'ID=3c504aa17c4a7048:T=1 ...
- SQL优化的七个方面
SQL优化的七个方面 1. 创建索引 禁止给表中每一列都建立单独索引 每个Innodb表都必须有一个主键 要注意组合索引的字段顺序 优先考虑覆盖索引 避免使用外键约束 2. 避免索引失效 失效场景: ...
- Nginx02 Nginx的的目录结构、基本工作原理、基本配置文件介绍
1 Nginx目录结构 1.1 简要介绍 [root@localhost ~]# tree /usr/local/nginx /usr/local/nginx ├── client_body_temp ...
- spring cloud alibaba - Nacos 下载安装
1.关于名字 前四个字母分别为Naming和Configuration的前两个字母,最后的s为Service 2.是什么 一个更易于构建云原生应用的动态服务发现,配置管理和服务管理中心.是注册中心和配 ...
- P9_组件-swiper和swiper-item的基本用法
swiper 和 swiper-item 组件的基本使用 实现如图的轮播图效果: swiper 组件的常用属性 list.wxml <swiper class="swiper-cont ...
- Could not execute query ---> MySql.Data.MySqlClient.MySqlException: You have an error in your SQL sy
1.出现问题 执行sql查询时出现如题错误,原因是安装mysql-connector-net的版本过高,当前项目在用的mysql版本不符合:关于当前安装的mysql-connector-net版本的查 ...
- uboot启动过程 1
打开 u-boot.lds OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-li ...
- NETAPP 设备 C模式开关机顺序
设备正常开关机顺序开机顺序: 1.开启所有磁盘柜的电源,大概20秒后再开启存储控制器: 2.开启接有FAS2750存储的以太网交换机或者光纤交换机: 3.开启有挂载FAS2750存储空间的服务器或者磁 ...