doupingmao1903 2015-09-25 12:29
浏览 9
已采纳

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

String is stored in database as unicode "\u0435\u043e ..." (table's encoding is UTF-8).

After selecting from database and printing:

log.Println(str)

OUT: \u0435\u043e...

How can I transform this string to utf presentation?

  • 写回答

1条回答 默认 最新

  • duanping1632 2015-09-25 12:33
    关注

    To decode the string you have, you can do:

    import "net/url"
    
    ...
    
    url.QueryUnescape("\u0435\u043e")
    

    But I think there's a misconfiguration of your database or connection parameters, as this should be handled automatically. This is not utf-8 BTW.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?