# json：无法将字符串解组到类型为 map[string]string 的 Go 结构体字段 Foo.Bar 中

- **ID:** `go/cannot-unmarshal-string-into-struct-field-of-type-map`
- **领域:** go
- **类别:** encoding_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

JSON 包含字符串值，但 Go 结构体期望映射类型，由于源数据中的 JSON 结构错误或类型不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## 解决方案

1. ```
   Change Go struct field type to string and parse manually: type Foo struct { Bar string } then unmarshal Bar as JSON string into map.
   ```
2. ```
   Preprocess JSON to ensure Bar is an object: use json.RawMessage to capture Bar, then check if it's a string and handle accordingly.
   ```

## 无效尝试

- **** — Tags only affect naming, not type conversion. (70% 失败率)
- **** — UseNumber() only affects number parsing, not type coercion. (80% 失败率)
