CKTIS / C#
System.Text.Json.JsonDocument: praktická reference
System.Text.Json.JsonDocument: praktická reference: JsonDocument parsuje JSON v UTF-8 do neměnného stromu nad sdíleným bufferem.
Verze: .NET API; verified against .NET 10 reference surface
Syntaxe
System.Text.Json.JsonDocument /* select a documented member or constructor */JsonDocument parsuje JSON v UTF-8 do neměnného stromu nad sdíleným bufferem.
Použijte k efektivnímu čtení dokumentu bez vytváření objektového modelu.
Musí být uvolněn; JsonElement závisí na jeho životnosti, pokud nepoužijete Clone.
Neplatný JSON vyhodí JsonException a chybějící vlastnost může vyhodit KeyNotFoundException.
Úplný program skutečně používá System.Text.Json.JsonDocument; přesně očekávaný stdout je 7.
Příklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
using var document = JsonDocument.Parse("{\"value\":7}");
Console.WriteLine(document.RootElement.GetProperty("value").GetInt32());
Výsledek
7
Úplný program skutečně používá `System.Text.Json.JsonDocument`; přesně očekávaný stdout je `7`.