CKTIS / C#
System.Text.Json.JsonSerializer: referência prática
System.Text.Json.JsonSerializer: referência prática: JsonSerializer converte valores .NET em JSON e vice-versa segundo contratos de tipos.
Versão: .NET API; verified against .NET 10 reference surface
Sintaxe
System.Text.Json.JsonSerializer /* select a documented member or constructor */JsonSerializer converte valores .NET em JSON e vice-versa segundo contratos de tipos.
Usa-o com modelos DTO, opções explícitas e um contexto source-generated sob AOT.
Nomes predefinidos, tratamento de null e campos nem sempre correspondem ao contrato externo.
JSON inválido lança JsonException; ciclos exigem configuração explícita.
O programa completo usa realmente System.Text.Json.JsonSerializer; o stdout exato esperado é [1,2].
Exemplos
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]
O programa completo usa realmente `System.Text.Json.JsonSerializer`; o stdout exato esperado é `[1,2]`.