go json 序列化 反序列化 报错 invalid character i looking for beginning of value
目录
问题
go json 对字符串、字节 进行反序列化时报错:
invalid characag-0-1iopkhk6jag-1-1iopkhk6jter 'ï' looking for beginning of value
原因:
The server is sending you a UTF-8 text
string with a Byte Order Mark (BOM).
The BOM identifies that the text is UTF-8 encoded,
but it should be removed before decoding.
大概意思就是说:字符串字节中存在特殊字符(BOM),导致 json 反序列化失败
解决
对特殊字符 BOM 进行处理
// Or []byte{239, 187, 191}
body = bytes.TrimPrefix(body, []byte("\xef\xbb\xbf"))