rabbitMq消息接收转换对象,Json解析字符串报错syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62解决
Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $
syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62
syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62
以上的报错都是Json字符串格式错误,比如缺少{},比如两头多了”“,或者转义字符\",比如在映射的对象错误,本来是List,但是写成了String,或者是单个对象,而不是List,都会报错。
1.在本地运行main方法排查解决
2.如果是多了”“,或者是内部多了转义字符\",则使用简单的替换方法。
比如完整的Json字符串格式如下:
{"err_no":"0","err_tips":"success","data":{"refund_list":[{"refund_id":"ots7240038790928135","out_refund_no":"29160417157000010","refund_total_amount":1090,"refund_status":"PROCESSING","refund_at":0,"message":"","order_id":"ots72396406088135","item_order_detail":[{"item_order_id":"ots723969678768135","refund_amount":1090}],"merchant_audit_detail":"{\"deny_message\":\"\",\"need_refund_audit\":1,\"refund_audit_deadline\":16859682,\"audit_status\":\"TOAUDIT\"}","create_at":1685701000,"refund_source":2}],"refund_id":"ots72400387928135","out_refund_no":"2916041715168561000010","refund_total_amount":1090,"refund_status":"PROCESSING","refund_at":0,"message":"","order_id":"ots7239640656088135","item_order_detail":[{"item_order_id":"ots72396406578768135","refund_amount":1090}],"merchant_audit_detail":{"need_refund_audit":1,"refund_audit_deadline":168596282,"audit_status":"TOAUDIT","deny_message":""}}}
package com.example.core.mydemo.json2; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.reflect.TypeToken; public class JSONTest {
public static void main(String[] args) {
String msg = "\"orderNo\":\"50133310603299\",\"riskAccidentStatus\":\"1\",\"operator\":\"admin\"";
//Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $
//缺少的是{}
try {
MQReceiveCLevelRiskControlDTO cLevelRiskControlDTO = GsonUtils.convert(msg, new TypeToken<MQReceiveCLevelRiskControlDTO>() {});
System.out.println("gson1=" + GsonUtils.toJson(cLevelRiskControlDTO));
}catch (Exception e) {
MQReceiveCLevelRiskControlDTO cLevelRiskControlDTO = GsonUtils.convert("{"+msg+"}", new TypeToken<MQReceiveCLevelRiskControlDTO>() {});
System.out.println("gson2=" + GsonUtils.toJson(cLevelRiskControlDTO));
} //syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62
// MQReceiveCLevelRiskControlDTO cLevelRiskControlDTO2 = JSON.parseObject(msg, MQReceiveCLevelRiskControlDTO.class);
// System.out.println("gson2=" + GsonUtils.toJson(cLevelRiskControlDTO2)); //syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62
// MQReceiveCLevelRiskControlDTO cLevelRiskControlDTO3 = JSONObject.parseObject(msg, MQReceiveCLevelRiskControlDTO.class);
// System.out.println("gson3=" + GsonUtils.toJson(cLevelRiskControlDTO3)); }
}
解决方法:过滤json字符串格式
String msgNew = msg;
if(msg.startsWith("\"") && msg.endsWith("\"")){
msgNew = msg.substring(1,msg.length() - 1).replace("\\","");
}
rabbitMq消息接收转换对象,Json解析字符串报错syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62解决的更多相关文章
- C# string.Format json格式字符串报错”输入字符串的格式不正确“
当我们在string.Format中传入Json字符串时,会报”输入字符串的格式不正确“,这是因为json的"{"符号的问题,最开始我是想着用转义一下"{",但 ...
- JSON parse error: syntax error, expect {, actual error, pos 0, fastjson-version 1.2.58; nested exception is com.alibaba.fastjson.JSONExcetion: syntax error, except {, actual error, pos ...
这个报错信息告诉你,你提交的参数需要是json类型.所以,POST请求携带的数据需要序列化一下json.dumps(data).
- redis通过json方案存取对象com.alibaba.fastjson.JSONException: syntax error, expect
问题描述: redis基于json方案存取对象时报错:com.alibaba.fastjson.JSONException: syntax error, expect com.alibaba.fast ...
- ESL python调用C模块时传递unicode字符串报错问题解决
在是用freeswitch时利用ESL的python调用时传递字符串报错 TypeError: in method 'ESLconnection_api', argument 2 of type 'c ...
- iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."
将服务器返回的JSON string转化成字典时报错: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence ...
- artTemplate--使用artTemplate时,由于json对象属性有数字命名格式 导致调用报错 syntax error
案例 今天在使用artTemplate做开发时,遇到一个比较奇葩的问题,就是使用json对象去获取值得时候,报如下错误: Template Error <temp> function an ...
- iOS中空字符串报错
*参考: http://www.ithao123.cn/content-8030945.html *参考: http://www.cnblogs.com/ziyi--caolu/p/4825633.h ...
- rabbitmq - 消息接收,解析xml格式数据时异常:ERROR not well-formed (invalid token): line 4, column 46
ERROR alsv odoo.addons.cus_alsv.utils.alsv_about_mq.get_data_from_mq: parse_xml_data_from_mq: not we ...
- python 字符串报错问题
http://jingyan.baidu.com/article/25648fc1a96dd49191fd00c0.html 解决'ascii' codec can't encode characte ...
- 在 VSCode 中 Angular 的字符串报错的问题
使用 Angular 时,报错 [tslint] " should be ' 报错原因是因为 ESLint 的严格模式,限制了使用 ' ,甚至多一个空格都会报错. 我们只需要在 settin ...
随机推荐
- dotnet OpenXML 读取 PPT 内嵌 xlsx 格式 Excel 表格的信息
在 Office 中,可以在 PPT 里面插入表格,插入表格有好多不同的方法,对应 OpenXML 文档存储的更多不同的方式.本文来介绍如何读取 PPT 内嵌 xlsx 格式的表格的方法 读取方法和 ...
- 2019-11-29-如何入门-C++-AMP-教程
title author date CreateTime categories 如何入门 C++ AMP 教程 lindexi 2019-11-29 08:20:37 +0800 2018-2-13 ...
- 使用 Docker 搭建 gitea 私有仓库
一.准备材料 安装环境:linux 工具:docker 软件:MySql.gitea 二.安装Docker 安装Docker:https://www.cnblogs.com/jzcn/p/156937 ...
- .NET静态代码织入——肉夹馍(Rougamo)发布3.0
肉夹馍(https://github.com/inversionhourglass/Rougamo)通过静态代码织入方式实现AOP的组件,其主要特点是在编译时完成AOP代码织入,相比动态代理可以减少应 ...
- gin 单个文件函数 上传文件到本地目录里
// 单个文件 上传文件到本地目录里 // 调用方法 utils.UplaodFileToLocal(c) // author haima func UplaodFileToLocal(c *gin. ...
- C语言:约瑟夫问题——使用循环链表解决
传说有30个乘客同乘一条船,因为严重超载,加上风浪水作,危险万分.船长告诉乘客,只有将全船一半的乘客投入海 中,其余人才能幸免于难.他们约定了一个规则:30个人围成一圈,由第一个人数起,依次报数,数到 ...
- PAT 练习2-3 输出倒三角图案
结果: 本题要求编写程序,输出指定的由"*"组成的倒三角图案. 输入格式: 本题目没有输入. 输出格式: 按照下列格式输出由"*"组成的倒三角图案. 一般都用的 ...
- 复杂模式的两个List与Map合并为一个Map的拼接;笛卡尔乘积处理数据问题
简介 (Introduction): 背景 数据从多个表中获取,每个表的数据条数不是唯一的,最后结果要拼接成一个Map<String,Object>的模式封装所有数据,每个数据是一条. 结 ...
- AIRIOT答疑第7期|如何快速提升物联网项目交付速度?
平台+模板,套上就能用!贼拉快! AIRIOT提供物联网低代码平台+多套行业案例模板,针对于有明确项目的服务商,用平台已经配置好的节点数.功能模块.流程,直接上手干项目! AIRIOT解答: 多套物联 ...
- 物联网平台在AIoT领域8大场景应用
物联网平台技术在AIoT智慧物联领域的应用越来越深入,尤其是在智慧城市建设项目中,提供了强有力的技术底座工具支撑.ToG的项目需要"门当户对"的服务商具备完善的资质和靠谱的技术服务 ...