字典数组到平面列表

Bru*_*ino 0 .net c# ext.net

有没有更好的方法(特别是使用Linq)在以下json字符串中返回ID的List/IEnumerable?

string json = "[{\"Id\":38,\"Name\":\"Albert Einstein\",\"Document\":\"845.803.604-51\"},{\"Id\":102,\"Name\":\"Benoit Mandelbrot\",\"Document\":\"657.322.962-20\"},{\"Id\":86,\"Name\":\"Santos-Dumont Aerospace\",\"CpfCnpj\":\"24.195.152/0001-55\"}]";
Run Code Online (Sandbox Code Playgroud)

目前我有:

Dictionary<string, string>[] deserializedJSON = Ext.Net.JSON.Deserialize<Dictionary<string, string>[]>(json);

List<decimal> idList = new List<decimal>();

foreach (var item in deserializedJSON)
{
    foreach (var i in item)
    {
        if (i.Key == "Id")
            idList.Add(Convert.ToDecimal(i.Value));
    }
}
Run Code Online (Sandbox Code Playgroud)

SLa*_*aks 5

idList = deserializedJSON.Select(d => decimal.Parse(d["Id"]))
                         .ToList();
Run Code Online (Sandbox Code Playgroud)