猿问

MarshalJSON 错误,顶级后的无效字符“g”

我为我的 ID 创建了一个自定义类型:


type ID uint


func (id ID) MarshalJSON() ([]byte, error) {

    e, _ := HashIDs.Encode([]int{int(id)})

    fmt.Println(e) /// 34gj

    return []byte(e), nil

}


func (id *ID) Scan(value interface{}) error {

    *id = ID(value.(int64))

    return nil

}

我使用 HashIDs 包对我的 ID 进行编码,以便用户无法在客户端读取它们。但我收到此错误:


json:为类型 types.ID 调用 MarshalJSON 时出错:顶级值后的字符“g”无效


慕婉清6462132
浏览 134回答 1
1回答
随时随地看视频慕课网APP

相关分类

Go
我要回答