-9

我已经编码:

foreach (KeyValuePair<string, object> keyValuePair in items)
{
    if (keyValuePair.Key == "animals")
    {
        Dictionary<string, object> animal = new Dictionary<string, object>();
        animal.Add(keyValuePair.Key, keyValuePair.Value);
        object animalObject = keyValuePair.Value;
        foreach (??? in animalObject)
        {

        }
    }
    object fajny = keyValuePair.Value;

    result2 = fajny as ArrayCollection;
}

我想从animalObject对象循环字典元素:

http://scr.hu/0tgp/6dteu http://screenshu.com/static/uploads/temporary/1h/1p/05/3p9fyc.jpg

我不知道该怎么做。我无法在任何地方搜索帮助。

4

2 回答 2

1

您是否尝试遍历字典中的值:animal

    foreach (object animalObject in animal.Values)
    {

    }
于 2013-05-24T14:36:01.803 回答
1

您可以尝试强制转换为IEnumerable,但我建议尝试保留强类型。

foreach (KeyValuePair<string, object> keyValuePair in items)
{
    if (keyValuePair.Key == "animals")
    {
        Dictionary<string, object> animal = new Dictionary<string, object>();
        animal.Add(keyValuePair.Key, keyValuePair.Value);
        IEnumerable animalObject = keyValuePair.Value as IEnumerable;

        if(animalEnumerable != null)
        {
            foreach (object animalObj in animalEnumerable)
            {

            }
        }
    }
}
于 2013-05-24T14:37:13.497 回答