CKTIS / C#
System.Text.Json.JsonSerializer: praktická reference
System.Text.Json.JsonSerializer: praktická reference: JsonSerializer mapuje hodnoty .NET na JSON a zpět podle kontraktů typů.
Verze: .NET API; verified against .NET 10 reference surface
Syntaxe
System.Text.Json.JsonSerializer /* select a documented member or constructor */JsonSerializer mapuje hodnoty .NET na JSON a zpět podle kontraktů typů.
Použijte pro modely DTO s výslovnými volbami a kontextem source-generated pod AOT.
Výchozí názvy, zpracování null a pole ne vždy odpovídají externímu kontraktu.
Neplatný JSON vyhodí JsonException; cykly vyžadují výslovnou konfiguraci.
Úplný program skutečně používá System.Text.Json.JsonSerializer; přesně očekávaný stdout je [1,2].
Pří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ýsledek
[1,2]
Úplný program skutečně používá `System.Text.Json.JsonSerializer`; přesně očekávaný stdout je `[1,2]`.