从System.Collections.ObjectModel获取数据

时间:2017-12-11 15:03:46

标签: c#

我有一段代码

object Items = (object)js.ExecuteScript("return angular.element(document.getElementById('bank-list')).scope().items");

如果我尝试使用Console.WriteLine(Items);

输出System.Collections.ObjectModel.ReadOnlyCollection1[System.Object]

我的问题是:如何从对象获取数据?

应该在Items变量中的数据类似于:

[{"index": 383, "id": 12163, "count": 1676, "formattedCount": 1676}]

1 个答案:

答案 0 :(得分:1)

试试这个:

var items = js.ExecuteScript("return angular.element(document.getElementById('bank-list')).scope().items") as ReadOnlyCollection<object>;
if(items != null)
{
    foreach (obj obj in items)
    {
        Dictionary<string,object> dict = obj as Dictionary<string, object>;
        if (dict != null)
        {
             foreach(var val in dict.Values)
                 Console.WriteLine(val);
        }
    }
}