Search code examples
c#nestedkey-value

c# iterate over nested key value pair


I have a KeyValuePair<string,object> and the object is also a KeyValuePair. I have been trying to cast the object to a new KeyValuePair so that I can iterate through the values, but so far all attempts have failed. Does anyone have any ideas. Thanks.

var installers = manifestDict.Where(kvp => kvp.Key.Equals("Installers"));
foreach(var i in installers)
{
     var newKvp = i.Value;
     //how to cast this object to a new kvp?
}

enter image description here


Solution

  • It ended up that I needed to cast to a list first.

     foreach(var i in installers)
     {
          var newKvp = i.Value as List<object>;
          foreach(var z in newKvp)
          {
               var result = (Dictionary<object,object>) z;
          }
     }