1. 复现问题
今天在启动spring boot
项目报出如下错误:
Exception: Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
at [Source: (String)""{
""properties"" : { },
""id"" : ""34da7f2ba4ec41dba7acd0533018d3e7"",
""script"" : null,
""groupId"" : ""d0fe7c6e314c4572aeae38b7cea6ea50"",
""name"" : ""更新定时任务"",
""createTime"" : 1645515608643,
""updateTime"" : 1645515608643,
""lock"" : ""0"",
""method"" : ""POST"",
""path"" : ""/updateTimerTask"",
""parameters"" : [ ],
""option"" : ""[]"",
""requestBody"" : ""{\r\n\t\r\n}"",
""headers"" : [ ],
""paths"" : [ ],
""responseBody"" : null,
""des"[truncated 119 chars]; line: 1, column: 4]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2391) ~[jackson-core-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:735) ~[jackson-core-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.core.base.ParserBase._throwUnquotedSpace(ParserBase.java:1110) ~[jackson-core-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString2(ReaderBasedJsonParser.java:2155) ~[jackson-core-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString(ReaderBasedJsonParser.java:2126) ~[jackson-core-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.getValueAsString(ReaderBasedJsonParser.java:363) ~[jackson-core-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromString(StdDeserializer.java:262) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1495) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:196) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:186) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4674) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3629) ~[jackson-databind-2.13.1.jar:2.13.1]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3597) ~[jackson-databind-2.13.1.jar:2.13.1]
at org.ssssssss.magicapi.utils.JsonUtils.readValue(JsonUtils.java:75) ~[magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.MagicResourceStorage.read(MagicResourceStorage.java:51) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.MagicResourceStorage.readResource(MagicResourceStorage.java:68) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.lambda$null$102(DefaultMagicResourceService.java:214) [magic-api-2.0.1.jar:2.0.1]
at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_102]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.lambda$refreshGroup$103(DefaultMagicResourceService.java:214) [magic-api-2.0.1.jar:2.0.1]
at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_102]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.refreshGroup(DefaultMagicResourceService.java:210) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.lambda$null$99(DefaultMagicResourceService.java:191) [magic-api-2.0.1.jar:2.0.1]
at java.util.HashMap.forEach(HashMap.java:1288) ~[na:1.8.0_102]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.lambda$readAll$100(DefaultMagicResourceService.java:191) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.writeLock(DefaultMagicResourceService.java:892) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.readAll(DefaultMagicResourceService.java:188) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.lambda$read$98(DefaultMagicResourceService.java:178) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.writeLock(DefaultMagicResourceService.java:892) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.read(DefaultMagicResourceService.java:174) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.onApplicationEvent(DefaultMagicResourceService.java:901) [magic-api-2.0.1.jar:2.0.1]
at org.ssssssss.magicapi.core.service.impl.DefaultMagicResourceService.onApplicationEvent(DefaultMagicResourceService.java:37) [magic-api-2.0.1.jar:2.0.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:108) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$started$5(SpringApplicationRunListeners.java:78) ~[spring-boot-2.6.2.jar:2.6.2]
at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_102]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplicationRunListeners.started(SpringApplicationRunListeners.java:78) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2]
at com.jqp.admin.JqpAdminApplication.main(JqpAdminApplication.java:22) ~[classes/:na]
2. 分析问题
首先解释 Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
这句话的含义是什么,即非法的无引号字符((CTRL-CHAR,代码 13)):必须使用反斜杠进行转义才能包含在字符串值中
。
也就是说上述json数据出现了非法字符,需要将非法字符进行转义。
分析上述json部分数据看到,确实出现了非法字符,如下所示:
{
""properties"" : { },
""id"" : ""34da7f2ba4ec41dba7acd0533018d3e7"",
""script"" : null
}
使用在线json格式化查看如下图所示:
从图中也可以看到,出现了非法字符。
3. 解决问题
既然出现了非法字符串,要么删除非法的字符,要么使用\
进行转义。
- 删除非法字符
{
"properties": {},
"id": "34da7f2ba4ec41dba7acd0533018d3e7",
"script": null
}
- 使用
\
转义
{
"\"properties\"": {},
"\"id\"": "\"34da7f2ba4ec41dba7acd0533018d3e7\"",
"\"script\"": null
}
4. 问题总结
报出Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
这个问题的原因就是字符串中出现了非法字符,我们一般采用如下两种方式解决
-
删除非法字符串。
-
使用转义字符
\
将非法字符转义。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/99155.html