1
我想從MySQL解析使用傑克遜的yaml數據,但我得到錯誤說有一個特殊字符。我得到的錯誤是這樣的:傑克遜錯誤:不可接受的字符''(0x0)不允許特殊字符
com.fasterxml.jackson.databind.JsonMappingException: special characters are not allowed
[Source: [email protected]; line: 13, column: 68] (through reference chain: com.app.ResultContentModel["opinion"])
...
Caused by: com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException: special characters are not allowed
at [Source: [email protected]; line: 13, column: 68]
...
Caused by: unacceptable character '' (0x0) special characters are not allowed
in "'reader'", position 1027
我的依賴文件是這樣的:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.8.1</version>
</dependency>
我想使用正則表達式來替代它:
Pattern nonASCII = Pattern.compile("[^\\x00-\\x7f]");//("[^\\x00-\\x7f]");
resultContent = Normalizer.normalize(nonASCII.matcher(resultContent).replaceAll("");
ResultContentModel rc = mapper.readValue(resultContent, ResultContentModel.class);
但還是沒工作。我該怎麼辦?
嘗試鏈接另一個替換 - '.replaceAll(「[\\ x00 - \\ x08 \\ x0B \\ x0C \\ x0E - \\ x20] +」,「」)' –
它甚至未能識別yaml數據。 –
如果這是對我的評論的反饋,請注意,正則表達式不匹配任何YAML數據,而是刪除不需要的控制字符。 –