C#Json的用法

using Newtonsoft.Json;
class Student
{
     
    public String Name {
      get; set; }
    public int Age {
      get; set; }
}

```csharp
  Student student = new Student() {
      Name = "小明", Age = 18 };
            string jsonStr = JsonConvert.SerializeObject(student, Formatting.Indented);
            File.WriteAllText("2.dat", jsonStr);
            string readStr = File.ReadAllText("2.dat");

            Student getString = JsonConvert.DeserializeObject<Student>(readStr);

你可能感兴趣的:(c#)