gpt4 book ai didi

unicode - 如何在 Go 中将 unicode 字符串从数据库转换为 utf 字符串?

转载 作者:数据小太阳 更新时间:2023-10-29 03:06:44 24 4
gpt4 key购买 nike

字符串在数据库中存储为 unicode "\u0435\u043e ..."(表的编码为 UTF-8)。

从数据库中选择并打印后:

日志.Println(str)

输出:\u0435\u043e...

如何将此字符串转换为 utf 格式?

最佳答案

要解码你拥有的字符串,你可以这样做:

import "net/url"

...

url.QueryUnescape("\u0435\u043e")

但我认为您的数据库或连接参数配置错误,因为这应该是自动处理的。这不是 utf-8 顺便说一句。

关于unicode - 如何在 Go 中将 unicode 字符串从数据库转换为 utf 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32782239/

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