Json序列化更新好友列表

一、概述

使用Newtonsoft.Json开源库进行序列化

二、代码

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);
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/3xiaolonglong/p/11058021.html
今日推荐