# JsonSerializationException：类型“PlayerData”的 JSON 输入无效

- **ID:** `unity/script-invalid-json-serialization`
- **领域:** unity
- **类别:** data_error
- **错误码:** `JSON-101`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

传递给 JsonUtility.FromJson 的 JSON 字符串与目标类的预期结构不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2021.3 | active | — | — |
| Unity 2022.3 | active | — | — |
| Unity 2023.1 | active | — | — |

## 解决方案

1. ```
   在反序列化之前使用 JSON 验证器验证 JSON 字符串。确保字段与类结构完全匹配（区分大小写）。
   ```
2. ```
   在目标类上使用 [Serializable] 属性，并确保所有字段都是公共的或具有 [SerializeField]。
   ```

## 无效尝试

- **Wrap the JSON parsing in a try-catch block and ignore the exception.** — Ignoring the exception leads to null data and potential runtime errors later. (70% 失败率)
- **Use Newtonsoft.Json instead of JsonUtility without changing the input format.** — If the JSON is malformed, Newtonsoft.Json will also fail or produce unexpected results. (50% 失败率)
