• 遍历寻找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; }
            }
    
  • 相关阅读:
    pycharm 社区版运行flask app相关配置
    飞冰框架学习记录
    从上一次到现在总结2
    从上一次到今天的总结1
    mybatis 遇到空串无法判断
    Shell 脚本入门
    数据库批量插入数据
    Navicat for mysql 实现数据库自动备份
    自定义校验注解
    C++ 提高编程
  • 原文地址:https://www.cnblogs.com/myblogslh/p/4477947.html
Copyright © 2020-2023  润新知