Base de connaissancesCentre d’examen
FRFrançais
Choisir la langue13

CKTIS / C#

System.Text.Json.Nodes.JsonNode: référence pratique

System.Text.Json.Nodes.JsonNode: référence pratique: JsonNode représente un arbre JSON modifiable composé d’objets, tableaux et valeurs.

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

Syntaxe

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

JsonNode représente un arbre JSON modifiable composé d’objets, tableaux et valeurs.

À utiliser pour modifier précisément un document sans modèle statique.

Un nœud n’a qu’un parent ; sa réutilisation ailleurs exige un clone.

Parse peut renvoyer null pour le littéral null ; un accès avec le mauvais type lève une exception.

Le programme complet utilise réellement System.Text.Json.Nodes.JsonNode ; sa sortie stdout exacte attendue est 4.

Exemples

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

Résultat

4

Le programme complet utilise réellement `System.Text.Json.Nodes.JsonNode` ; sa sortie stdout exacte attendue est `4`.

Sources