# 错误：json：不支持的类型：chan int

- **ID:** `go/encoding-json-marshal-unsupported-type`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试对 encoding/json 不支持的Go类型进行编组，例如通道、函数或复数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **Implement json.Marshaler interface for the custom type** (90% 成功率)
   ```
   type MyChan chan int
func (c MyChan) MarshalJSON() ([]byte, error) {
    return json.Marshal(len(c))
}
   ```

## 无效尝试

- **Using reflect to manually marshal** — Complex and error-prone; better to implement json.Marshaler interface. (60% 失败率)
