使用json.RawMessage获取
inputs字段的原始JSON文本:
type Item struct { Type string `json:"type"` Inputs json.RawMessage}像这样使用它:
var data Configurationif err := json.Unmarshal([]byte(myJson), &data); err != nil { // handle error}// Loop over items and unmarshal items.Inputs to Go type specific// to each input type. for _, item := range data.Items { switch item.Type { case "type-of-item": var v struct{ Input1 string } if err := json.Unmarshal(item.Inputs, &v); err != nil { // handle error } fmt.Printf("%s has value %+vn", item.Type, v) }}在操场上跑。



