gpt4 book ai didi

java - jackson 错误: unacceptable character '' (0x0) special characters are not allowed

转载 作者:行者123 更新时间:2023-11-30 02:49:34 26 4
gpt4 key购买 nike

我正在尝试使用 MySQL 中的 jackson 解析 yaml 数据,但收到错误消息,提示存在特殊字符。我收到类似这样的错误:

com.fasterxml.jackson.databind.JsonMappingException: special characters are not allowed 
[Source: java.io.StringReader@5528a42c; 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: java.io.StringReader@5528a42c; 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);

但是还是没成功。我该怎么办?

最佳答案

您似乎想要将任何非 ASCII + 所有字符与从 0020(空格)的十六进制代码匹配。

使用

Pattern nonASCII = Pattern.compile("[^\\x00-\\x7f]+|[\\x00-\\x20]+");

\x00-\x20 将匹配您需要删除的所有控制字符,[^\x00-\x7f] 将匹配非 ASCII 字符。

+量词会匹配1次或多次,从而一次性删除/替换匹配到的字符 block 。

关于java - jackson 错误: unacceptable character '' (0x0) special characters are not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39116848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com