简体   繁体   中英

How to access object in array( Dynamic DataType) with foreach loop in C#

在此处输入图片说明

Big Picture

i have this dynamic object. it is an array of object. i want to do a foreach loop in this object array.

i can foreach for a single object like below

 foreach (KeyValuePair<dynamic, dynamic> pair in jsonstaticobj1232)
            {
                dwt.Add(pair.Key, pair.Value);

            }

but how to foreach loop in a obj array?

Try this

for(int=0;i<jsonstaticobj1232.Length;i++)
{

foreach (KeyValuePair<dynamic, dynamic> pair in jsonstaticobj1232[i])
        {
            dwt.Add(pair.Key, pair.Value);

        }
}

foreach loop for dynamic object in array.

foreach (dynamic dObject in mArray)
{

}
       List<string> layers = new List<string>();
       var dict = jss.Deserialize<Dictionary<string, dynamic>>(json);
                foreach (Dictionary<string,dynamic> key in dict["layers"])
                {
                    key.TryGetValue("name", out layersDic);
                    layers.Add(layersDic);
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM