B
B
bogac2019-04-30 00:26:08
go
bogac, 2019-04-30 00:26:08

Convert Interface{} to Map?

Good evening of the day!
Tell me please. There is the following code and the following structure:

func AddToMap(decoded interface{}) (map[string]interface{}) {
  v := reflect.ValueOf(decoded)
  if v.Kind() == reflect.Map {
    for t, key := range v.MapKeys() {
      strct := v.MapIndex(key)
      if key.Interface().(string) == "KeyN" {
        (///////-----///////)?????
      }
    }
  }
  return UserData
}

Пример структуры:
Map["key1":"value1", map["key2"]:{"value2, ... ,valueN"}, .... , map["KeyN":[map["NeedKey"]:{"NeedValue1, NeedValue2"}]]....]

After getting all the map, I need to get further to the map with the "NeedKey" key.
It is of type Interface{} and I have not found a way to iterate over the values ​​of this map.
Translation using:
k := reflect.ValueOf(strct)
for _, values:= range k.MapKeys() {
.....
}

results in an error.
Please help and some clarification.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question