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

- **ID:** `python/starlette-request-body-parsing`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求体为空或不是有效的 JSON，但尝试用 request.json() 解析。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Check content-type first: if request.headers.get('content-type') == 'application/json':
    data = await request.json()
else:
    return JSONResponse(status_code=415)
   ```
2. **** (85% 成功率)
   ```
   Use a middleware to parse JSON and handle errors gracefully.
   ```

## 无效尝试

- **** — Works but masks the root cause; better to validate request content type. (50% 失败率)
- **** — body() returns bytes; need to decode and json.loads. (60% 失败率)
