# JSON 解码错误：期望值：第 1 行第 1 列（字符 0）

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

## 根因

请求体为空或不是有效的 JSON，尝试解析时出错。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Check request.body is not empty and content-type is application/json before parsing.
   ```
2. **** (90% 成功率)
   ```
   Use try-except: try: data = json.loads(request.body) except json.JSONDecodeError: return HttpResponseBadRequest('Invalid JSON')
   ```

## 无效尝试

- **** — Using json.loads(request.body) without checking content type can raise error. (90% 失败率)
- **** — Catching JSONDecodeError with broad except hides the real issue. (40% 失败率)
