错误消息: JSON parsing failed: Text: org.springframework.web.servlet.mvc.method.anno...
🚨 错误信息
错误名称: AI_ProviderSpecificError
错误消息: JSON parsing failed: Text: org.springframework.web.servlet.mvc.method.annotation.SseEmitter$SseEventBuilderImpl@3cf07406.
Error message: JSON Parse error: Unexpected character: o
堆栈跟踪: AI_ProviderSpecificError: JSON parsing failed: Text: org.springframework.web.servlet.mvc.method.annotation.SseEmitter$SseEventBuilderImpl@3cf07406.
Error message: JSON Parse error: Unexpected character: o
at construct (native)
at _callSuper (address at index.android.bundle:1:278429)
at _AISDKError (address at index.android.bundle:1:5445273)
at construct (native)
at _callSuper (address at index.android.bundle:1:278429)
at ProviderSpecificError (address at index.android.bundle:1:5465586)
at convertAndEmitChunk (address at index.android.bundle:1:5462374)
at ?anon_0_ (address at index.android.bundle:1:5461652)
at next (native)
at asyncGeneratorStep (address at index.android.bundle:1:844868)
at _next (address at index.android.bundle:1:845125)
at tryCallOne (address at InternalBytecode.js:1:1180)
at anonymous (address at InternalBytecode.js:1:1874)
原因: {
"name": "AI_JSONParseError",
"cause": {},
"text": "org.springframework.web.servlet.mvc.method.annotation.SseEmitter$SseEventBuilderImpl@3cf07406"
}
🤖 AI解决方案
错误分析报告
#### 1. 误翻译
原文:JSON Parse error: Unexpected character: o
译文:JSON解析错误:遇到意外字符‘o’
#### 2 原因分析
org.springframework.web...@3cf07406)作为JSON数据发送给了前端,而不是有效的JSON格式数据。text 字段内容并非合法的JSON字符串,因此在解析时因首个字符o(来自org.)不符合JSON语法而失败。SseEventBuilder)的环节。开发者可能错误地将事件构建器对象本身或其toString()结果,当作事件数据(data)发送了。#### 3.方案
修复后端代码,确保通过 SseEmitter 发送的是可序列化的数据对象或字符串,而不是对象引用。
java
// 错误示范 ❌ - 直接发送了对象引用或其字符串
SseEmitter.SseEventBuilder event = SseEmitter.event()
.data(someObject.toString()); // 如果 someObject 是复杂对象,其toString()可能是地址// 正确示范 ✅ - 发送对象本身,让 Spring 自动序列化为 JSON
SseEmitter.SseEventBuilder event = SseEmitter.event()
.data(myDataObject); // 确保 myDataObject 可以被 Jackson 序列化
// 或者明确发送一个已格式化的 JSON 字符串
SseEmitter.SseEventBuilder event = SseEmitter.event()
.data("{\"key\": \"value\", \"message\": \"这是一条有效的JSON消息\"}");
修复步骤:
SseEmitter 事件的逻辑。.data(...) 方法中传入的参数。SseEventBuilderImpl 对象本身或其他未重写 toString() 的对象。#### 4️ 预防措施
convertAndEmitChunk 函数中,增加对 text 字段的预检查,例如使用 try-catch 包裹JSON解析逻辑,并对解析失败的情况进行日志记录和友好处理。