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 關注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消