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; } }
时间: 2024-10-19 22:04:16