样本:
{
"id": 1
"data": {"1": 2}
}
结构定义:
type Item struct {
id int `json:"id"`
data interface{} `json:"data"`
}
我需要从 http 帖子中解析有效负载,所以我使用interface{}fordata是json.Unmarshal()成功的,但是 gorm 在调用时会产生错误db.Create(item):
(sql: converting Exec argument #5's type: unsupported type map[string]interface {}, a map)
相反,我从 更改interface{}为string,调用json.Unmarshal()解析 json POST 有效负载会产生错误。
unmarshal type error: expected=string, got=object
基本上,一个需要interface{},一个需要string。
有人遇到过这个吗?