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. [Docker] 使 Volume 独立于容器运行时的方式 - 让容器引擎去处理

    在单纯使用 run 命令运行一个容器时,通常会使用 -v 挂载的方式来实现宿主机数据卷映射到容器内. 使用命令: $ docker run --name mysql-con -v /my/custom ...

  2. WPF 触摸下如何给 StylusPointCollection 添加点

    本文告诉大家如何在触摸下给 WPF 的 StylusPointCollection 添加新的点 在自己默认创建的 StylusPointCollection 里面添加点是十分简单的,如以下代码,可以非 ...

  3. dotnet core 3.1 将 UWP 控件嵌入到 WPF 应用 收到 UIA 消息主线程卡住

    本文记录一个问题,此问题是在 .NET Core 3.1 的 WPF 应用里面,嵌入 UWP 控件之后,在收到 UIA 的消息时,可能让主线程卡住.暂时此问题还不知道具体的复现步骤,此问题预计和 WP ...

  4. 一个库帮你轻松的创建漂亮的.NET控制台应用程序

    前言 做过.NET控制台应用程序的同学应该都知道原生的.NET控制台应用程序输出的内容都比较的单调,假如要编写漂亮且美观的控制台输出内容或者样式可能需要花费不少的时间去编写代码和调试.今天大姚给大家分 ...

  5. 登录信息localStorage存储

    localStorage拓展了cookie的4K限制,与sessionStorage的唯一一点区别就是localStorage属于永久性存储,而sessionStorage属于当会话结束的时候,ses ...

  6. SpringBoot使用JSch操作Linux

    推荐使用Hutool的Jsch工具包(它用的连接池的技术) 一.SSH远程连接服务器 SSH更多见:http://t.csdnimg.cn/PrsNv 推荐连接工具:FinalShell.Xshell ...

  7. SAP集成技术(二)接口库

    目前还没有一个集中的地方能找到全部SAP接口,它们分散在几个不同的地方. 本文链接:https://www.cnblogs.com/hhelibeb/p/17843509.html 内容部分来自< ...

  8. PostgreSQL数据库管理工具pgAdmin4界面如何设置为中文显示

    首发微信公众号:SQL数据库运维 原文链接:https://mp.weixin.qq.com/s?__biz=MzI1NTQyNzg3MQ==&mid=2247485130&idx=1 ...

  9. 1分钟了解什么是SQL聚合函数,一看就懂,一学就会!(AVG(column_name)\COUNT(column_name)\MAX(column_name)\MIN(column_name)\SUM(column_name))

    聚集函数:SQL基本函数,聚集函数对一组值执行计算,并返回单个值,也被称为组函数.聚集函数经常与SELECT语句的GROUP BY子句的HAVING一同使用.但是不可用于WHERE语句中,因为WHER ...

  10. 🔥httpsok彻底告别SSL证书续期烦扰

    httpsok彻底告别SSL证书续期烦扰 介绍 httpsok 是一个便捷的 HTTPS 证书自动续签工具,专为 Nginx .OpenResty 服务器设计.已服务众多中小企业,稳定.安全.可靠. ...