# 错误：字符串字面量中存在无效的UTF-8

- **ID:** `go/encoding-json-invalid-utf8-in-string`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

JSON输入在字符串中包含无效的UTF-8字节序列，违反了JSON规范。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **Use json.Decoder with DisallowUnknownFields and validate input** (85% 成功率)
   ```
   decoder := json.NewDecoder(reader)
decoder.DisallowUnknownFields()
if err := decoder.Decode(&target); err != nil { /* handle */ }
   ```

## 无效尝试

- **Using strings.Replace to remove non-UTF8 characters** — May corrupt data; better to use utf8.ValidString and reject or sanitize. (70% 失败率)
