Is there a better way (specially using Linq) to return a List/IEnumerable of the IDs in the following json string?
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\"}]";
Currently I have:
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));
}
}
1 Answer