go
type_error
ai_generated
true
error: json: unsupported type: chan int
ID: go/json-marshal-unsupported-type
80%Fix Rate
87%Confidence
0Evidence
2024-03-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.19 | active | — | — | — |
Root Cause
尝试将 Go 中不支持 JSON 序列化的类型(如 channel、complex、func)传递给 json.Marshal。
generic中文
尝试将 Go 中不支持 JSON 序列化的类型(如 channel、complex、func)传递给 json.Marshal。
Workarounds
-
90% success
func (c MyChan) MarshalJSON() ([]byte, error) { return json.Marshal(c.String()) } -
85% success
type MyStruct struct { Data []int `json:"data"` }
Dead Ends
Common approaches that don't work:
-
80% fail
会丢失类型信息,且无法还原为原始数据。
-
60% fail
如果该字段是必须的,忽略会导致数据不完整。