1 回答
TA贡献1847条经验 获得超11个赞
在Golang中是别名,当您使用它时,它返回与您的数据类型相同的类型。因此,当您收到此类数据时,它会转换为字符串。byteuint8json.Marshal[]byte
您需要将 uint8 强制转换为其他 int 类型或实现Marshaler interface
投
bytes, err := service.GetValue()
value := make([]int8, 0)
for _, v := range bytes {
value = append(value, int8(v))
}
元帅
type CustomType []uint8
func (u CustomType) MarshalJSON() ([]byte, error) {
var result string
if u == nil {
result = "null"
} else {
result = strings.Join(strings.Fields(fmt.Sprintf("%d", u)), ",")
}
return []byte(result), nil
}
func GetValue(c echo.Context) error {
var value CustomType
bytes, err := service.GetValue()
value = bytes
return c.JSON(http.StatusOK, value)
}
- 1 回答
- 0 关注
- 112 浏览
添加回答
举报
