# 值错误：无效的JSON：期望属性名用双引号括起来

- **ID:** `python/fastapi-valueerror-json-encode-error`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求体包含无效的JSON语法（例如单引号而不是双引号）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Use proper JSON formatting** (95% 成功率)
   ```
   {"name": "John", "age": 30}
   ```
2. **Use json.dumps() to convert Python object** (90% 成功率)
   ```
   import json
json.dumps({'name': 'John'})
   ```

## 无效尝试

- **Assuming JSON allows single quotes** — JSON standard requires double quotes for strings. (90% 失败率)
- **Using Python dict directly in JSON body** — Python dict representation is not valid JSON. (70% 失败率)
