例如,如果我有一個(gè)interface{}最初是 amap[string]map[int64][]int64或任何其他類(lèi)型地圖的值,如何獲取地圖的鍵類(lèi)型?或更準(zhǔn)確地說(shuō),如何將其轉(zhuǎn)換為map[theKeyType]interface{}?func Transverse(any interface{}) string { res := `` switch any.(type) { case string: return `` case []byte: return `` case int, int64, int32: return `` case float32, float64: return `` case bool: return `` case map[int64]interface{}: return `` case map[string]interface{}: return `` case []interface{}: return `` default: kind := reflect.TypeOf(any).Kind() switch kind { case reflect.Map: // how to convert it to map[keyType]interface{} ? } return `` // handle other type } return ``}
將接口轉(zhuǎn)換為其對(duì)應(yīng)的地圖
料青山看我應(yīng)如是
2021-09-13 10:28:10