Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.Text.Json.JsonSerializer: referencia práctica

System.Text.Json.JsonSerializer: referencia práctica: JsonSerializer convierte valores .NET a JSON y viceversa según contratos de tipos.

Versión: .NET API; verified against .NET 10 reference surface

Sintaxis

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

JsonSerializer convierte valores .NET a JSON y viceversa según contratos de tipos.

Úsalo con modelos DTO, opciones explícitas y un contexto source-generated bajo AOT.

Los nombres predeterminados, el tratamiento de null y los campos no siempre coinciden con el contrato externo.

Un JSON no válido lanza JsonException; los ciclos requieren configuración explícita.

El programa completo usa realmente System.Text.Json.JsonSerializer; su stdout esperado exacto es [1,2].

Ejemplos

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

Resultado

[1,2]

El programa completo usa realmente `System.Text.Json.JsonSerializer`; su stdout esperado exacto es `[1,2]`.

Fuentes