Last active
July 26, 2020 11:30
-
-
Save jsakamoto/471e84fc739919326c6a849ebf216086 to your computer and use it in GitHub Desktop.
Study of System.Text.Json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"sdk": { | |
"version": "3.1.300", | |
"rollForward": "latestPatch" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace StudyOfSystemTextJson | |
{ | |
public class Person | |
{ | |
public string Name { get; } | |
public int Age { get; } | |
public Person(string name, int age) | |
{ | |
Name = name; | |
Age = age; | |
} | |
public override string ToString() => $"{Name}, {Age}"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text.Json; | |
namespace StudyOfSystemTextJson | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var person = new Person( | |
name: "Taro", | |
age: 23 | |
); | |
var jsonText = JsonSerializer.Serialize(person); | |
Console.WriteLine(jsonText); | |
var newPerson = JsonSerializer.Deserialize<Person>(jsonText); | |
Console.WriteLine(newPerson.ToString()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
<LangVersion>8.0</LangVersion> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="System.Text.Json" Version="5.0.0-preview.7.20364.11" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment