Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Text.Json.Nodes.JsonNode: odniesienie praktyczne

System.Text.Json.Nodes.JsonNode: odniesienie praktyczne: JsonNode reprezentuje modyfikowalne drzewo JSON z obiektami, tablicami i wartościami.

Wersja: .NET API; verified against .NET 10 reference surface

Składnia

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

JsonNode reprezentuje modyfikowalne drzewo JSON z obiektami, tablicami i wartościami.

Stosuj do punktowych zmian dokumentu bez statycznego modelu.

Węzeł ma jednego rodzica; do ponownego użycia w innym miejscu potrzebny jest klon.

Parse może zwrócić null dla literału null; błędny typ dostępu zgłasza wyjątek.

Kompletny program rzeczywiście używa System.Text.Json.Nodes.JsonNode; oczekiwany stdout to dokładnie 4.

Przykłady

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;

var node = JsonNode.Parse("{\"x\":4}")!;
Console.WriteLine(node["x"]!.GetValue<int>());

Wynik

4

Kompletny program rzeczywiście używa `System.Text.Json.Nodes.JsonNode`; oczekiwany stdout to dokładnie `4`.

Źródła