База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / C#

System.Text.Json.JsonDocument: практическа справка

System.Text.Json.JsonDocument: практическа справка: JsonDocument анализира UTF-8 JSON в неизменяемо дърво върху споделен буфер.

Версия: .NET API; verified against .NET 10 reference surface

Синтаксис

System.Text.Json.JsonDocument /* select a documented member or constructor */

JsonDocument анализира UTF-8 JSON в неизменяемо дърво върху споделен буфер.

Използвайте за ефективно четене на документ без създаване на обектен модел.

Трябва да се освободи; JsonElement зависи от живота му, освен ако се използва Clone.

Невалиден JSON хвърля JsonException, а липсващо свойство може да хвърли KeyNotFoundException.

Пълната програма действително използва System.Text.Json.JsonDocument; точният очакван stdout е 7.

Примери

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());

Резултат

7

Пълната програма действително използва `System.Text.Json.JsonDocument`; точният очакван stdout е `7`.

Източници