遍历寻找json中的重复数据
string str = "[{\"ID\":1,\"Data\":{\"subjectCode\":\"1\",\"subjectName\":\"1\",\"subjectType\":\"1\",\"componentFormat\":\"2\"}},{\"ID\":2,\"Data\":{\"subjectCode\":\"1\",\"subjectName\":\"2\",\"subjectType\":\"1\",\"componentFormat\":\"2\"}},{\"ID\":4,\"Data\":{\"subjectCode\":\"1\",\"subjectName\":\"1\",\"subjectType\":\"1\",\"componentFormat\":\"2\"}}]"; JavaScriptSerializer jss = new JavaScriptSerializer(); List<A> aList = jss.Deserialize<List<A>>(str); for (int i = 0; i < aList.Count - 1; i++) { int index = i + 1; A a = aList[i]; while (index < aList.Count) { A b = aList[index]; if (a.Data.subjectCode.Equals(b.Data.subjectCode) && a.Data.subjectName.Equals(b.Data.subjectName) && a.Data.subjectType.Equals(b.Data.subjectType) && a.Data.componentFormat.Equals(b.Data.componentFormat)) { string message = a.ID + "=" + b.ID; Console.WriteLine(message); break; } index++; } } Console.ReadKey(); } public class A { public int ID { get; set; } public B Data { get; set; } } public class B { public string subjectCode { get; set; } public string subjectName { get; set; } public string subjectType { get; set; } public string componentFormat { get; set; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。