var js = new System.Web.Script.Serialization.JavaScriptSerializer(); string json = "{\"offlineLock\":[{\"id\":\"4028d808581dab0f01581db51405001e\",\"mac\":\"D4:3D:7E:5F:B7:44\",\"sdsl\":5,\"sdrq\":1477967156304,\"shlb\":\"0\"}],\"flag\":\"success\",\"status\":\"1400\",\"resultList\":[{\"id\":\"4028d808581dab0f01581db5145c001f\",\"zwjyzsbh\":\"1000001600000052\",\"sfyfz\":\"0\"},{\"id\":\"4028d808581dab0f01581db514780020\",\"zwjyzsbh\":\"1000001600000054\",\"sfyfz\":\"0\"},{\"id\":\"4028d808581dab0f01581db514950021\",\"zwjyzsbh\":\"1000001600000056\",\"sfyfz\":\"0\"},{\"id\":\"4028d808581dab0f01581db514b20022\",\"zwjyzsbh\":\"1000001600000058\",\"sfyfz\":\"0\"},{\"id\":\"4028d808581dab0f01581db514cc0023\",\"zwjyzsbh\":\"1000001600000060\",\"sfyfz\":\"0\"}]}"; var jarr = js.Deserialize<Dictionary<string, object>>(json); foreach(var j in jarr) { Console.WriteLine(string.Format("{0}:{1}", j.Key, j.Value)); } Console.ReadLine();
通过下标循环Dictionary的键值集合
for (int i = 0; i < jarr.Count; i++) { var item = jarr.ElementAt(i);//获取字典的下标为i的<key,value>值 var itemKey = item.Key; //获取上面得到的key值 var itemValue = item.Value;//获取上面得到的value值
}
时间: 2024-10-27 06:12:01