Hello World

菜死我了,代码如下

using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Json_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Student s1 = new Student(1, "张三");
            Student s2 = new Student(2, "李四");
            List<Student> sss = new List<Student>();
            sss.Add(s1);
            sss.Add(s2);
            sss.Add(new Student(6, "李刚"));
            sss.Add(new Student(Convert.ToInt32(Console.ReadLine()), Console.ReadLine()));
            string jsonString = JsonConvert.SerializeObject(sss);
            Console.WriteLine("总Json:" + jsonString);
            foreach (var student in sss)
            {
                jsonString = JsonConvert.SerializeObject(student);
                Console.WriteLine("每个学生Json:" + jsonString);
            }
            Console.ReadKey();

        }
    }
}

标签: C#, Json

添加新评论