1.install-package System.Text.Json
2.
static void SystemTextJsonJsonSerializerDemo() { var obj = new { Id = 1, Name = "Fred", Age = 34 }; string jsonValue = System.Text.Json.JsonSerializer.Serialize(obj); Console.WriteLine(jsonValue); }
3.Result:
{"Id":1,"Name":"Fred","Age":34}