Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

System.Text.Json.JsonSerializer: praktická referencia

System.Text.Json.JsonSerializer: praktická referencia: JsonSerializer mapuje hodnoty .NET na JSON a späť podľa kontraktov typov.

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

Syntax

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

JsonSerializer mapuje hodnoty .NET na JSON a späť podľa kontraktov typov.

Použite pre modely DTO s výslovnými voľbami a kontextom source-generated pod AOT.

Predvolené názvy, spracovanie null a polia nie vždy zodpovedajú externému kontraktu.

Neplatný JSON vyhodí JsonException; cykly vyžadujú výslovnú konfiguráciu.

Úplný program skutočne používa System.Text.Json.JsonSerializer; presne očakávaný stdout je [1,2].

Príklady

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

Výsledok

[1,2]

Úplný program skutočne používa `System.Text.Json.JsonSerializer`; presne očakávaný stdout je `[1,2]`.

Zdroje