# proto: （第 1 行第 14 列）：未知字段 "userName"

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

## 根因

protojson.Unmarshal 遇到了与目标消息任何字段都不匹配的 JSON 键。protobuf JSON 使用 proto 字段名（snake_case）或 lowerCamelCase 的 JSON 名；使用不相关的命名会失败。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   opts := protojson.UnmarshalOptions{DiscardUnknown: true}
if err := opts.Unmarshal(data, msg); err != nil {
    return err
}
   ```
2. **** (88% 成功率)
   ```
   // .proto: string user_name = 1;
// JSON accepts either:
// {"user_name":"alice"}  or  {"userName":"alice"}
   ```

## 无效尝试

- **** — encoding/json ignores protobuf-specific semantics (oneofs, well-known types) and produces incorrect values. (80% 失败率)
- **** — Fragile and breaks for nested messages, repeated fields, and oneofs; also loses type info. (60% 失败率)
