如何从字典列表中获取密钥

时间:2014-07-13 12:15:28

标签: c# list dictionary

我有jsondata以字典列表的形式出现..我需要从每次迭代中取出Key和value

这就是我试过的......

var json = new WebClient().DownloadString(url);

JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Dictionary<string,object>> json = serializer.Deserialize<List<Dictionary<string,object>>>(json);

foreach (Dictionary<string, object> record in jsonList )
{
    var imei = record.Keys;
}

上面的代码返回另一个Keys数组,我必须在其中选择First Element。

这在每次迭代中都会发生......我需要单个Key.Not数组键

1 个答案:

答案 0 :(得分:0)

试试这个

var keys = json.Select(d => d.Keys.First()).ToList();

将返回每个字典中的第一个键

相关问题