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解决的更多相关文章

  1. C# string.Format json格式字符串报错”输入字符串的格式不正确“

    当我们在string.Format中传入Json字符串时,会报”输入字符串的格式不正确“,这是因为json的"{"符号的问题,最开始我是想着用转义一下"{",但 ...

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

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

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

  4. ESL python调用C模块时传递unicode字符串报错问题解决

    在是用freeswitch时利用ESL的python调用时传递字符串报错 TypeError: in method 'ESLconnection_api', argument 2 of type 'c ...

  5. iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."

    将服务器返回的JSON string转化成字典时报错: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence ...

  6. artTemplate--使用artTemplate时,由于json对象属性有数字命名格式 导致调用报错 syntax error

    案例 今天在使用artTemplate做开发时,遇到一个比较奇葩的问题,就是使用json对象去获取值得时候,报如下错误: Template Error <temp> function an ...

  7. iOS中空字符串报错

    *参考: http://www.ithao123.cn/content-8030945.html *参考: http://www.cnblogs.com/ziyi--caolu/p/4825633.h ...

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

  9. python 字符串报错问题

    http://jingyan.baidu.com/article/25648fc1a96dd49191fd00c0.html 解决'ascii' codec can't encode characte ...

  10. 在 VSCode 中 Angular 的字符串报错的问题

    使用 Angular 时,报错 [tslint] " should be ' 报错原因是因为 ESLint 的严格模式,限制了使用 ' ,甚至多一个空格都会报错. 我们只需要在 settin ...

随机推荐

  1. 重磅发布:微服务引擎 MSE 专业版

    简介: 性能提升 10 倍,更高的 SLA 保障,新用户限时抢购 8 折资源包. 微服务引擎 MSE 专业版发布,支持 Nacos 2.0 ,相比基础版,专业版具有更高的 SLA 保障,性能提升十倍, ...

  2. 慢SQL治理分享

    简介: 这里的慢SQL指的是MySQL慢查询,是运行时间超过long_query_time值的SQL.真实的慢SQL通常会伴随着大量的行扫描.临时文件排序或者频繁的磁盘flush,直接影响就是磁盘IO ...

  3. 阿里云重磅发布业务中台产品 BizWorks,中台发展进入下一个阶段

    ​简介: 业务中台产品BizWorks重磅发布,这可以看作是阿里云在 "做厚中台" 战略上继 "云钉一体"之后的又一个新动作! 10 月 19 日,2021 云 ...

  4. GRPC: 如何实现分布式日志跟踪?

    ​简介: 本文将介绍如何在 gRPC 分布式场景中,实现 API 的日志跟踪. 介绍 本文将介绍如何在 gRPC 分布式场景中,实现 API 的日志追踪. 什么是 API 日志追踪? 一个 API 请 ...

  5. [BlockChain] 三方互惠是公共区块链得以发展的基石, dApp数字通证的运转需要可持续性玩法

    ------------------------------- 公链 旷工    开发者/用户 ------------------------------- -------------------- ...

  6. WPF 对接 Vortice 绘制 WIC 图片

    本文告诉大家如何通过 Vortice 在 Direct2D 里面绘制图片,图片的来源是 WIC 加载出的图片 在上一篇博客 WPF 对接 Vortice 调用 WIC 加载图片 告诉了大家如何对接 V ...

  7. 从 Rollover+curator 到 ILM

    数据量增长,当前存在的问题: 查询与写入越来越慢,聚合的速度慢的离谱,聚合的数据量大一些的话,可能出现超时失败,甚至OOM 磁盘和内存资源以肉眼可见的速度快速消耗,甚至出现满载的情况 JVM频繁GC, ...

  8. idea在商店无法搜索到插件

    背景:我使用的版本是IDEA ultimate 2019.2 版本印象中,最初安装的时候,商店还是可以用的,突然有一天,就无法使用了.下边直入正题: 解决办法:1.首先浏览器登陆下:https://p ...

  9. go1.18泛型全部教程

    目录 go1.18泛型全部教程 一 什么是泛型 二 Golang中的泛型 三 泛型语法详解 3.1 泛型的语法 3.2 Constraint(约束)是什么 3.3 自定义constraint(约束) ...

  10. Gitee千Star优质项目解析: ng-form-element低开引擎解析

    好家伙, 在写项目的时候,我发现自己的平台的组件写的实在是太难看了,于是想去gitee上偷点东西,于是我们本期的受害者出现了 gitee项目地址 https://gitee.com/jjxliu306 ...