JSON经典异常:: Unterminated string at character

时间:2025-02-07 18:55:17

案发情景:

手机终端与Java以JSON数据格式方式进行数据交互;

出现异常完整信息如下:

Unterminated string at character 89 of {"events":[{"otherMsg":": Error receiving broadcast Intent  act
at (:451)
at (:219)
at (:316)
at .<init>(:206)
at (:319)
at .<init>(:126)
at (:323)
at .<init>(:206)
at .<init>(:327)
at (:74)


经过测试得出结论:

发送JSON数据格式不正确,

即:

 手机终端那边 抛出的异常信息然后直接放到Json字符串中,而异常信息里面有多个换行或者空格以及特殊字符,然后再通过上报接口传送到Java这边,接着Java这边解析时导致解析json报异常 。

简单测试语句:

JSONObject js = new JSONObject("{\"events\":[{\"otherMsg\":\": Error receiving broadcast Intent  act");



解决方法:

规范化数据格式;