# System.Text.Json.JsonException: JSON 值无法转换为 System.String。路径: $.propertyName | 行号: 1 | 字节位置: 20。

- **ID:** `dotnet/serialization-json-ignore-attribute`
- **领域:** dotnet
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

System.Text.Json 反序列化失败，因为 JSON 属性类型不匹配（例如数字而非字符串）或缺失，通常由模型属性不匹配（如 JsonIgnore）引起。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| System.Text.Json 6.0.x | active | — | — |
| System.Text.Json 7.0.x | active | — | — |
| System.Text.Json 8.0.x | active | — | — |

## 解决方案

1. ```
   Add a custom JsonConverter to handle type conversion, e.g., convert number to string.
   ```
2. ```
   Use JsonSerializerOptions.Converters to register converter globally.
   ```
3. ```
   Change the C# model property type to object or JsonElement and handle casting manually.
   ```

## 无效尝试

- **** — Adding JsonSerializerOptions.IgnoreNullValues doesn't fix type mismatches. (95% 失败率)
- **** — Changing the JSON source to match the C# model is often not feasible in production. (80% 失败率)
- **** — Using JsonSerializerOptions.PropertyNameCaseInsensitive only helps with casing, not types. (90% 失败率)
