# 恐慌：json：为类型main.MyType调用MarshalJSON时使用了不可寻址的值

- **ID:** `go/encoding-json-marshal-non-addressable-value`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试编组一个不可寻址的值，例如映射键，无法调用其方法。

## 版本兼容性

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

## 解决方案

1. **Ensure MarshalJSON has pointer receiver and pass pointer** (90% 成功率)
   ```
   func (m *MyType) MarshalJSON() ([]byte, error) { ... }
// Always pass pointer
json.Marshal(&myValue)
   ```

## 无效尝试

- **Using reflect to make it addressable** — Complex and may panic; better to use pointer receiver. (70% 失败率)
