# proto：（第 1 行第 2 列）：pb.User 中未知字段 "user_id"

- **ID:** `go/proto-unknown-field-json`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

protojson.Unmarshal 遇到目标消息中不存在的 JSON 字段。常见于 JSON 使用 snake_case 而 proto 字段使用 camelCase（protojson 默认），或 JSON 来自不同 schema 版本。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| google.golang.org/protobuf 1.26+ | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Use protojson with explicit options:
opts := protojson.UnmarshalOptions{
    DiscardUnknown: true,
}
err := opts.Unmarshal(data, msg)
   ```
2. **** (85% 成功率)
   ```
   Configure the emitter/unmarshaler for the naming convention you expect:
protojson.UnmarshalOptions{Resolver: ...}
// and emit with UseProtoNames to force snake_case:
m := protojson.MarshalOptions{UseProtoNames: true}
   ```

## 无效尝试

- **** — protojson returns a partial message; downstream code sees zero values and produces wrong results. (85% 失败率)
- **** — Generated protobuf structs do not honor json tags; protojson uses its own field-name mapping. (90% 失败率)
