Json序列化更新好友列表

1、概述this

使用Newtonsoft.Json開源庫進行序列化spa

 

2、代碼code

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonStudy
{
    public class Student
    {
        public string Name;
        public int Age;
        public Student(string name, int age)
        {
            this.Name = name;
            this.Age = age;
        }
        public Student()
        {

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            List<Student> studentList = new List<Student>()
            {

                new Student() { Name = "Tom", Age = 33},
                 new Student { Name = "Mary", Age = 36},
                new Student("Alice", 25)
            };
            string str = JsonConvert.SerializeObject(studentList);

            List<Student> list = JsonConvert.DeserializeObject<List<Student>>(str);
            Console.WriteLine(str);
        }
    }
}
相關文章
相關標籤/搜索