# 无效字符 '\x00'，正在查找值的开头

- **ID:** `go/json-invalid-character-looking-for-beginning`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

JSON 解码器输入以 NUL 字节或非 JSON 垃圾开头，例如二进制内容、BOM 或空 gzip 流。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **** (85% 成功率)
   ```
   b = bytes.TrimPrefix(b, []byte{0xEF,0xBB,0xBF})
b = bytes.Trim(b, "\x00")
if !json.Valid(b) { return fmt.Errorf("invalid json: %q", b[:min(32,len(b))]) }
   ```
2. **** (90% 成功率)
   ```
   Log the first 64 bytes of the body before decoding to diagnose the actual content.
   ```

## 无效尝试

- **** — Does not remove NUL bytes or BOM. (80% 失败率)
- **** — Returns false but gives no insight into the cause. (60% 失败率)
