我有一个数据库 sql.NullBool。为了将json反序列化到其中,我编写了这个小函数。我可以通过简单地进行转换(string(data))将字节数组转换为字符串...但是对于布尔值不行。你有什么想法可以将其转换为布尔值吗?
type NullBool struct {
sql.NullBool
}
func (b *NullBool) UnmarshalJSON(data []byte) error {
b.Bool = bool(data) //BREAKS!!
b.Valid = true
return nil
}