CKTIS / C#
System.Text.Json.JsonSerializer: référence pratique
System.Text.Json.JsonSerializer: référence pratique: JsonSerializer convertit les valeurs .NET en JSON et inversement selon les contrats de type.
Version : .NET API; verified against .NET 10 reference surface
Syntaxe
System.Text.Json.JsonSerializer /* select a documented member or constructor */JsonSerializer convertit les valeurs .NET en JSON et inversement selon les contrats de type.
À utiliser pour des DTO avec des options explicites et un contexte source-generated sous AOT.
Les noms par défaut, la gestion de null et les champs ne correspondent pas toujours au contrat externe.
Un JSON invalide lève JsonException ; les cycles exigent une configuration explicite.
Le programme complet utilise réellement System.Text.Json.JsonSerializer ; sa sortie stdout exacte attendue est [1,2].
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;
Console.WriteLine(JsonSerializer.Serialize(new[] { 1, 2 }));
Résultat
[1,2]
Le programme complet utilise réellement `System.Text.Json.JsonSerializer` ; sa sortie stdout exacte attendue est `[1,2]`.