go
type_error
ai_generated
true
panic: json: unsupported type: chan int
ID: go/json-marshal-channels
80%Fix Rate
90%Confidence
0Evidence
2024-03-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
Root Cause
尝试将channel或函数等不支持的类型序列化为JSON。
generic中文
尝试将channel或函数等不支持的类型序列化为JSON。
Workarounds
-
95% success
在结构体中使用`json:"-"`忽略字段: type Message struct { Ch chan int `json:"-"` Data string `json:"data"` } -
80% success
实现MarshalJSON方法自定义序列化。
Dead Ends
Common approaches that don't work:
-
100% fail
程序崩溃。
-
90% fail
json.Marshal不处理channel。