c# - Iterate through an ExpandoObject that contains multiple ExpandoObjects -


i wondered if possible iterate on expandoobject contains array of expando objects?

i parsing json file structure below:

"event":       [{     "name": "begin!",     "count": 1 }], "context":       {      "customer": {         "greetings":            [            {  "value1": "hello" },            {  "value2": "bye" }           ],         "nicknames": []     } } 

i can retrieve expando object 'event' doing following:

generatedictionary(((expandoobject[])dict["event"])[0], dict, "event_"); 

this code generatedictionary method:

private void generatedictionary(system.dynamic.expandoobject output, dictionary<string, object> dict, string parent)     {         try         {             foreach (var v in output)             {                 string key = parent + v.key;                 object o = v.value;                  if (o.gettype() == typeof(system.dynamic.expandoobject))                 {                     generatedictionary((system.dynamic.expandoobject)o, dict, key + "_");                 }                 else                 {                     if (!dict.containskey(key))                     {                         dict.add(key, o);                     }                 }             }         }         catch (exception ex)         {             writetolog(itemname, ex);         }     } 

i totally stuck on how retrieve values in 'context_customer_greetings' when attempt below, retrieve object @ context_customer_greetings_value1.

    generatedictionary(((system.dynamic.expandoobject[])dict["context_customer_greetings"])[0], dict, "context_customer_greetings_"); 

is possible iterate through expandoobject?

i hope makes sense, thanking in advance.

i have found solution (albeit simple one!)

i created new dynamic object , iterate across using same method above.

     dynamic s = dict["context_custom_greetings"];      foreach(expandoobject o in s)      {         generatedictionary((expandoobject)o, dict, "context_custom_greetings_");      } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -