在mysql中从json列中解码unicode字符串。

问题描述 投票:0回答:1

我在mysql上有一个json列,包含这样的值。

{"value_1": "Cancu00fan", "value_2":"Other value"}

我试图得到value_1属性 我要求该值被解码("Cancún"), 我这样做:

SELECT convert(json_field->>"$.value_1" USING latin1) FROM example_table;

但我还是得到:

"Cancu00fan"

当我做插入的数据,我插入的数据为:

 {"value_1": "Cancún", "value_2":"Other value"}

但是MySQL会自动编码,有什么建议吗?

mysql json decode
1个回答
0
投票

不是我想要的,但对我来说是可行的

    CREATE DEFINER=`root`@`localhost` FUNCTION `convertunicode`(encoded varchar(100))    RETURNS varchar(100) CHARSET utf8mb4 BEGIN DECLARE decoded VARCHAR(20); SET decoded = encoded; SET decoded = replace(decoded, "u00e1", "á");        SET decoded = replace(decoded, "u00e9", "é"); SET decoded = replace(decoded, "u00ed", "í"); SET decoded = replace(decoded, "u00f3", "ó"); SET decoded = replace(decoded, "u00fa", "ú")。       SET decoded = replace(decoded, "u00c1", "Á"); SET decoded = replace(decoded, "u00c9", "É"); SET decoded = replace(decoded, "u00cd", "Í"); SET decoded = replace(decoded, "u00d3", "Ó")。       SET decoded = replace(decoded, "u00da", "Ú"); SET decoded = replace(decoded, "u00f1", "ñ"); SET decoded = replace(decoded, "u00d1", "Ñ"); RETURN decoded; END
© www.soinside.com 2019 - 2024. All rights reserved.