Json序列化

JsonSerializer

目录

代码

Json序列化是将对象转化成字符串

using System.Text.Json;
class Program
{
    static void Main()
    {
        People people = new People();
        people.age = 20;
        people.Name = "A";
        people.Email = "abc@qq.com";

        //Json 序列化
        string a = JsonSerializer.Serialize(people);
        Console.WriteLine(a);
    }
}

public class People
{
    public string Name { get; set; }
    public int age { get; set; }
    public string Email { get; set; }
}

输出

{"Name":"A","age":20,"Email":"abc@qq.com"}

此条目发表在C#分类目录。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注