特殊符号的编码,需要查看ascii编码表

通过字符串的replaceAll方法,可以替换字符串中的特殊符号:

content = content.replaceAll("[\\x00-\\x09\\x11\\x12\\x14-\\x1F\\x7F]", "");

如果想要打印出特殊符号,或者表达特殊符号,可以利用下面的方法:

例如第一个字符:

System.out.println((char)0);

String s1 = String.valueOf((char) 0);
String s2 = new String(new char[]{0});
String s3 = new String(Character.toChars(0));

其他相关

空字符导致的报错日志: 

2024-06-20 17:21:26.155 ERROR 5584 --- [6884333_inbound] c.g.u.ParseUtils : 
parse content error, content:,
error: No content to map due to end-of-input at [Source: (String)""; line: 1, column: 0]

非json的数据解析报错

ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> result = objectMapper.readValue(content, HashMap.class);
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: 
Unrecognized token 'a': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"a"; line: 1, column: 2]
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: 
Illegal character ((CTRL-CHAR, code 0)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (String)" "; line: 1, column: 2]

mqtt连接中断 

2024-06-22 14:23:03.017 ERROR 5584 --- [8 1719037171987] c.g.m.MqttPushCallback : connectionlost:【已断开连接】,
trace:【[org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:189), java.lang.Thread.run(Unknown Source)]】
paho java mqtt EOFexception connectionLost

更多推荐