# json.JSONDecodeError: 期望值：第1行第1列（字符0）

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

## 根因

视图尝试将request.body解析为JSON，但请求体为空或不是有效的JSON。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Check if request.body is empty before parsing: if not request.body: return JsonResponse({'error': 'Empty body'}, status=400)
   ```
2. **** (90% 成功率)
   ```
   Wrap json.loads in try-except and return 400 with error message.
   ```

## 无效尝试

- **** — Hides the actual error and makes debugging difficult; still fails for malformed input. (80% 失败率)
- **** — request.POST only parses form data, not JSON payloads, so it will be empty. (90% 失败率)
