easyjson []uint8 预编译为[]byte的一个坑
2019-04-24 本文已影响0人
ricktian_e963
//easyjson:json
type Teststruct {
SubId []uint8 `json:"sub_ids"`
}
easyjson预编译后的代码为:
case "sub_ids":
if in.IsNull() {
in.Skip()
out.SubId = nil
}else {
out.SubId = in.Bytes()
}
按照[]byte来用了,如果以下json解码就会失败:
"{\"sub_ids\":[1,2,4]}"
报错如下:
parse error: expected string near offset 37 of 'sub_ids'
标准库encoding/json不会有此问题。