go data_error ai_generated true

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

invalid character '\x00' looking for beginning of value

ID: go/json-invalid-character-looking-for-beginning

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2024-07-03首次发现

版本兼容性

版本状态引入弃用备注
1.18 active — — —
1.22 active — — —

根因分析

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

English

The input to the JSON decoder begins with a NUL byte or non-JSON garbage, e.g. binary content, BOM, or an empty gzip stream.

generic

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 80% 失败

    Does not remove NUL bytes or BOM.

  2. 60% 失败

    Returns false but gives no insight into the cause.