参考サイト
docs.microsoft.com
sample code
using System;
using static System.Console;
using System.IO;
using System.Text;
using System.Text.Json;
namespace JsonDocTest
{
class Program
{
static void Main(string[] args)
{
var json = JsonDocument.Parse(File.ReadAllText("files/test.json", Encoding.UTF8));
WriteLine(json.RootElement.GetProperty("name").ToString());
WriteLine(json.RootElement.GetProperty("name").GetRawText());
WriteLine(json.RootElement.GetProperty("age").ToString());
WriteLine(json.RootElement.GetProperty("address").GetProperty("countory").ToString());
WriteLine(json.RootElement.GetProperty("address").GetProperty("city").ToString());
var name =json.RootElement.GetProperty("name");
WriteLine(name.ValueKind);
var address = json.RootElement.GetProperty("address");
WriteLine(address.ValueKind);
var ids = json.RootElement.GetProperty("ids");
WriteLine(ids.ValueKind);
foreach (var item in ids.EnumerateArray())
{
WriteLine(item);
}
var d = json.RootElement.GetProperty("dust");
WriteLine(d.ValueKind);
WriteLine(d);
}
}
}