首页 > Web开发 > 详细

遍历寻找json中的重复数据

时间:2015-05-04 23:59:20      阅读:493      评论:0      收藏:0      [点我收藏+]
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; }
        }

 

遍历寻找json中的重复数据

原文:http://www.cnblogs.com/myblogslh/p/4477947.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!