Json-->Newton.Json.dll的使用方法

Newton.Json.dll  for .NET2.0

实体1

public class Student
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
    }

实体2

public class Classroom
    {
        public string ID { get; set; }
        public string CName { get; set; }
        public List<Student> stds { get; set; }
    }

初始化

 Student st1 = new Student
            {
                ID = "11",
                Name = "cw",
                Age = 1
            };
            Student st2 = new Student
            {
                ID = "12",
                Name = "wjb",
                Age = 2
            };
            List<Student> std = new List<Student>();
            std.Add(st1);
            std.Add(st2);
            Classroom cls1 = new Classroom
            {
                ID = "23",
                CName = "1班",
                stds = std
            };

 string xx= JsonConvert.SerializeObject(cls1);

返回结果:

{"ID":"23","CName":"1班","stds":[{"ID":"11","Name":"cw","Age":1},{"ID":"12","Name":"wjb","Age":2}]}

Json-->Newton.Json.dll的使用方法,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。