来自 webhook 的 MySQL 中的字符 \x92 错误
Character \x92 error in MySQL from webhook
我的 Spring 引导应用程序出现 SQL 异常,提示 Caused by: java.sql.SQLException: Incorrect string value: '\x92s.","...' for column 'json' at row 1
。这很可能意味着我从 webhook 获取数据为 latin-1 或 Windows 1252。我确实看到两种类型的撇号,'
和 ’
。我的数据库设置为 utf8mb4
.
我觉得这有点奇怪,因为我过去常常以相反的方式得到错误。如何检查发送数据的编码? / 我该如何解决这个问题?
webhook 来自 Typeform。当我通过 "test webhook" 发送测试请求时,我在 Chrome 开发工具中查看响应 header 选项卡时看到各种 \u2019
和类似代码。所以这必须是unicode。我有点困惑为什么 MySQL 将其解释为 latin-1。
当我在保存之前在后端打印出字符串时,我看到它是 unicode 格式的。为什么?由于以下原因:单词 collega's
在 unicode (see a converter here) 中写为 \x63\x6f\x6c\x6c\x65\x67\x65\x61\x27\x73
,十进制为 99 111 108 108 101 103 97 39 115
。这就是我得到的。 ’
是 \xe2\x80\x99
或十进制 226 128 153
.
当我调试 Mysql.IO.class
时,我看到字符编码是 WINDOWS-1252
。那是罪魁祸首,但这组在哪里?嗯...不知何故 JDBC driver 在 Connectionimpl.class
.
中的以下代码中执行此操作
String encoding = null;
if (this.getUseUnicode()) {
encoding = this.getEncoding();
}
哇...问题是在我的开发版本中我没有在 URL 中指定字符编码。但是,我确实在我的生产构建中这样做了。这就是它在生产中而不是在开发中工作的原因。
我需要从我的生产环境添加查询参数:useUnicode=true&characterEncoding=utf8
。
我的 Spring 引导应用程序出现 SQL 异常,提示 Caused by: java.sql.SQLException: Incorrect string value: '\x92s.","...' for column 'json' at row 1
。这很可能意味着我从 webhook 获取数据为 latin-1 或 Windows 1252。我确实看到两种类型的撇号,'
和 ’
。我的数据库设置为 utf8mb4
.
我觉得这有点奇怪,因为我过去常常以相反的方式得到错误。如何检查发送数据的编码? / 我该如何解决这个问题?
webhook 来自 Typeform。当我通过 "test webhook" 发送测试请求时,我在 Chrome 开发工具中查看响应 header 选项卡时看到各种 \u2019
和类似代码。所以这必须是unicode。我有点困惑为什么 MySQL 将其解释为 latin-1。
当我在保存之前在后端打印出字符串时,我看到它是 unicode 格式的。为什么?由于以下原因:单词 collega's
在 unicode (see a converter here) 中写为 \x63\x6f\x6c\x6c\x65\x67\x65\x61\x27\x73
,十进制为 99 111 108 108 101 103 97 39 115
。这就是我得到的。 ’
是 \xe2\x80\x99
或十进制 226 128 153
.
当我调试 Mysql.IO.class
时,我看到字符编码是 WINDOWS-1252
。那是罪魁祸首,但这组在哪里?嗯...不知何故 JDBC driver 在 Connectionimpl.class
.
String encoding = null;
if (this.getUseUnicode()) {
encoding = this.getEncoding();
}
哇...问题是在我的开发版本中我没有在 URL 中指定字符编码。但是,我确实在我的生产构建中这样做了。这就是它在生产中而不是在开发中工作的原因。
我需要从我的生产环境添加查询参数:useUnicode=true&characterEncoding=utf8
。