1 回答

蛊毒传说
TA贡献1895条经验 获得超3个赞
如果您有未修复的密钥,则可以使用的唯一方法是 interface{} 您需要将 json 解组为[]interface{}并使用类型断言map[string]interface{}
var body []interface{}
_ = json.Unmarshal([]byte(json2), &body)
fmt.Printf("Unmarshaled: %v\n", body)
// range through array interface[]
for _, opt := range body {
// assert interface{} to map[string]interface{}
if item, ok := opt.(map[string]interface{}); ok {
for v, opt := range item {
fmt.Printf("[%s] key -> %s value -> %s\n", v, opt, "fake")
}
}
}
基于您的示例的完整代码 https://play.golang.org/p/PepxOVlB7u4
- 1 回答
- 0 关注
- 134 浏览
添加回答
举报
0/150
提交
取消