charmap.ISO8859_9.NewEnprer()。Bytes()函数要使用UTF-8格式进行编码。尝试对字节进行编码时出现错误。因为我的传入字节是8859-9格式,所以我试图直接将它们转换。首先,我将字节解码为UTF-8格式。我做了我的过程,最后我使用编码器将此UTF-8字节编码为ISO8859-9
unipre。这是新代码。
//main packagebytes, err := textproc.R.ReadBytes(constant.EndTextDelimiter)checkError(err)msg := enprer.DepreISO8859_9ToUTF8(bytes)//..........// Process that string, create struct Then convert struct to json bytes// Then enpre that bytesjson := enprer.EnpreUTF8ToISO8859_9(bytes)//enprer packagepackage enprerimport "golang.org/x/text/encoding/charmap"func DepreISO8859_9ToUTF8(bytes []byte) string { enpred, _ := charmap.ISO8859_9.NewDeprer().Bytes(bytes) return string(enpred[:])}func EnpreUTF8ToISO8859_9(bytes []byte) string { enpred, _ := charmap.ISO8859_9.NewEnprer().Bytes(bytes) return string(enpred[:])}


