先解决乱码 我这里用的是restTemplate
ResponseEntity<String> postForEntity = restTemplate.getForEntity(getUserInfoUrl, String.class);
String json = postForEntity.getBody();
if (json != null){
//解决乱码
return new String(json.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
}
保存到Mysql会报错
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x98\xA0&a...' for column 'name' at row 1
utf-8占用3个字节,但是表情会占用4个 如果是老版本的数据库直接升级,然后设置数据库编码里面的utf8 全部替换成utf8mb4 再设置字段的编码
ALTER TABLE ttt MODIFY COLUMN name VARCHAR(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
完事