JsonSerializer.Serialize Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Přetížení
| Name | Description |
|---|---|
| Serialize(Object, JsonTypeInfo) |
Převede zadanou Stringhodnotu na hodnotu . |
| Serialize(Stream, Object, JsonTypeInfo) |
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru . |
| Serialize(Object, Type, JsonSerializerOptions) |
Převede hodnotu zadaného typu na řetězec JSON. |
| Serialize(Object, Type, JsonSerializerContext) |
Převede zadanou Stringhodnotu na hodnotu . |
| Serialize(Utf8JsonWriter, Object, JsonTypeInfo) |
Zapisuje do zadaného zapisovače jednu hodnotu JSON (včetně objektů nebo polí). |
| Serialize(Stream, Object, Type, JsonSerializerOptions) |
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru . |
| Serialize(Stream, Object, Type, JsonSerializerContext) |
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru . |
| Serialize(Utf8JsonWriter, Object, Type, JsonSerializerOptions) |
Zapíše reprezentaci JSON zadaného typu do zadaného zapisovače. |
| Serialize(Utf8JsonWriter, Object, Type, JsonSerializerContext) |
Zapisuje do zadaného zapisovače jednu hodnotu JSON (včetně objektů nebo polí). |
| Serialize<TValue>(Utf8JsonWriter, TValue, JsonTypeInfo<TValue>) |
Zapisuje do zadaného zapisovače jednu hodnotu JSON (včetně objektů nebo polí). |
| Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions) |
Zapíše reprezentaci JSON typu určeného parametrem obecného typu do zadaného zapisovače. |
| Serialize<TValue>(Stream, TValue, JsonTypeInfo<TValue>) |
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru . |
| Serialize<TValue>(TValue, JsonSerializerOptions) |
Převede hodnotu typu určeného parametrem obecného typu na řetězec JSON. |
| Serialize<TValue>(TValue, JsonTypeInfo<TValue>) |
Převede zadanou Stringhodnotu na hodnotu . |
| Serialize<TValue>(Stream, TValue, JsonSerializerOptions) |
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru . |
Serialize(Object, JsonTypeInfo)
Převede zadanou Stringhodnotu na hodnotu .
public:
static System::String ^ Serialize(System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static string Serialize(object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member Serialize : obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> string
Public Function Serialize (value As Object, jsonTypeInfo As JsonTypeInfo) As String
Parametry
- value
- Object
Hodnota, kterou chcete převést.
- jsonTypeInfo
- JsonTypeInfo
Metadata o typu, který chcete převést.
Návraty
Reprezentace String hodnoty.
Výjimky
jsonTypeInfo je null.
valueneodpovídá typu .jsonTypeInfo
Poznámky
String Použití není tak efektivní jako použití kódování UTF-8, protože implementace interně používá UTF-8. Viz také SerializeToUtf8Bytes(Object, JsonTypeInfo) a SerializeAsync(Stream, Object, JsonTypeInfo, CancellationToken).
Platí pro
Serialize(Stream, Object, JsonTypeInfo)
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru .
public:
static void Serialize(System::IO::Stream ^ utf8Json, System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static void Serialize(System.IO.Stream utf8Json, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member Serialize : System.IO.Stream * obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> unit
Public Sub Serialize (utf8Json As Stream, value As Object, jsonTypeInfo As JsonTypeInfo)
Parametry
- value
- Object
Hodnota, kterou chcete převést.
- jsonTypeInfo
- JsonTypeInfo
Metadata o typu, který chcete převést.
Výjimky
utf8Json je null.
valueneodpovídá typu .jsonTypeInfo
Platí pro
Serialize(Object, Type, JsonSerializerOptions)
Převede hodnotu zadaného typu na řetězec JSON.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static string Serialize(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static string Serialize(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static string Serialize(object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static string Serialize(object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : obj * Type * System.Text.Json.JsonSerializerOptions -> string
Public Function Serialize (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As String
Public Shared Function Serialize (value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing) As String
Parametry
- value
- Object
Hodnota, kterou chcete převést.
- inputType
- Type
Typ převodu value .
- options
- JsonSerializerOptions
Možnosti pro řízení chování převodu
Návraty
Řetězcová reprezentace json hodnoty.
- Atributy
Výjimky
inputType není kompatibilní s value.
inputType je null.
Pro serializovatelné členy není kompatibilní JsonConverterinputType .
Poznámky
String Použití není tak efektivní jako použití kódování UTF-8, protože implementace interně používá UTF-8. Viz také SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) a SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).
Další informace naleznete v tématu Jak serializovat a deserializovat JSON.
Platí pro
Serialize(Object, Type, JsonSerializerContext)
Převede zadanou Stringhodnotu na hodnotu .
public:
static System::String ^ Serialize(System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static string Serialize(object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member Serialize : obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> string
Public Function Serialize (value As Object, inputType As Type, context As JsonSerializerContext) As String
Parametry
- value
- Object
Hodnota, kterou chcete převést.
- inputType
- Type
Typ převodu value .
- context
- JsonSerializerContext
Zprostředkovatel metadat pro serializovatelné typy.
Návraty
Reprezentace String hodnoty.
Výjimky
Pro serializovatelné členy není kompatibilní JsonConverterinputType .
Metoda GetTypeInfo(Type) zadaného context návratu null pro typ, který se má převést.
inputType nebo context je null.
Poznámky
String Použití není tak efektivní jako použití kódování UTF-8, protože implementace interně používá UTF-8. SerializeToUtf8Bytes(Object, Type, JsonSerializerContext) Viz a SerializeAsync(Stream, Object, Type, JsonSerializerContext, CancellationToken).
Platí pro
Serialize(Utf8JsonWriter, Object, JsonTypeInfo)
Zapisuje do zadaného zapisovače jednu hodnotu JSON (včetně objektů nebo polí).
public:
static void Serialize(System::Text::Json::Utf8JsonWriter ^ writer, System::Object ^ value, System::Text::Json::Serialization::Metadata::JsonTypeInfo ^ jsonTypeInfo);
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Text.Json.Serialization.Metadata.JsonTypeInfo jsonTypeInfo);
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * System.Text.Json.Serialization.Metadata.JsonTypeInfo -> unit
Public Sub Serialize (writer As Utf8JsonWriter, value As Object, jsonTypeInfo As JsonTypeInfo)
Parametry
- writer
- Utf8JsonWriter
Zapisovač, který se má psát.
- value
- Object
Hodnota pro převod a zápis.
- jsonTypeInfo
- JsonTypeInfo
Metadata o typu, který chcete převést.
Výjimky
writer nebo jsonTypeInfo je null.
valueneodpovídá typu .jsonTypeInfo
Platí pro
Serialize(Stream, Object, Type, JsonSerializerOptions)
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru .
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize (utf8Json As Stream, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Parametry
- value
- Object
Hodnota, kterou chcete převést.
- inputType
- Type
Typ převodu value .
- options
- JsonSerializerOptions
Možnosti pro řízení chování převodu
- Atributy
Výjimky
inputType není kompatibilní s value.
utf8Json nebo inputType je null.
Pro serializovatelné členy není kompatibilní JsonConverterinputType .
Platí pro
Serialize(Stream, Object, Type, JsonSerializerContext)
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru .
public:
static void Serialize(System::IO::Stream ^ utf8Json, System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static void Serialize(System.IO.Stream utf8Json, object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member Serialize : System.IO.Stream * obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> unit
Public Sub Serialize (utf8Json As Stream, value As Object, inputType As Type, context As JsonSerializerContext)
Parametry
- value
- Object
Hodnota, kterou chcete převést.
- inputType
- Type
Typ převodu value .
- context
- JsonSerializerContext
Zprostředkovatel metadat pro serializovatelné typy.
Výjimky
inputType není kompatibilní s value.
utf8Json, inputTypenebo context je null.
Pro serializovatelné členy není kompatibilní JsonConverterinputType .
Platí pro
Serialize(Utf8JsonWriter, Object, Type, JsonSerializerOptions)
Zapíše reprezentaci JSON zadaného typu do zadaného zapisovače.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, Type inputType, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object value, Type inputType, System.Text.Json.JsonSerializerOptions options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Public Shared Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, Optional options As JsonSerializerOptions = Nothing)
Parametry
- writer
- Utf8JsonWriter
Zapisovač JSON, do který se má zapisovat.
- value
- Object
Hodnota pro převod a zápis.
- inputType
- Type
Typ převodu value .
- options
- JsonSerializerOptions
Možnosti řízení chování serializace
- Atributy
Výjimky
inputType není kompatibilní s value
writer nebo inputType je null.
Pro serializovatelné členy není kompatibilní JsonConverterinputType .
Poznámky
Použitý JsonWriterOptions k vytvoření instance Utf8JsonWriter má přednost před konfliktem JsonSerializerOptions . Proto se JsonWriterOptions.IndentedJsonWriterOptions.SkipValidationpři psaní používají a JsonWriterOptions.Encoder používají se.
Další informace naleznete v tématu Jak serializovat a deserializovat JSON.
Platí pro
Serialize(Utf8JsonWriter, Object, Type, JsonSerializerContext)
Zapisuje do zadaného zapisovače jednu hodnotu JSON (včetně objektů nebo polí).
public:
static void Serialize(System::Text::Json::Utf8JsonWriter ^ writer, System::Object ^ value, Type ^ inputType, System::Text::Json::Serialization::JsonSerializerContext ^ context);
public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, Type inputType, System.Text.Json.Serialization.JsonSerializerContext context);
static member Serialize : System.Text.Json.Utf8JsonWriter * obj * Type * System.Text.Json.Serialization.JsonSerializerContext -> unit
Public Sub Serialize (writer As Utf8JsonWriter, value As Object, inputType As Type, context As JsonSerializerContext)
Parametry
- writer
- Utf8JsonWriter
Zapisovatel JSON, do který se má zapisovat.
- value
- Object
Hodnota pro převod a zápis.
- inputType
- Type
Typ převodu value .
- context
- JsonSerializerContext
Zprostředkovatel metadat pro serializovatelné typy.
Výjimky
inputType není kompatibilní s value.
writer nebo inputType je null.
Pro serializovatelné členy není kompatibilní JsonConverterinputType .
Metoda GetTypeInfo(Type) zadaného context návratu null pro typ, který se má převést.
Platí pro
Serialize<TValue>(Utf8JsonWriter, TValue, JsonTypeInfo<TValue>)
Zapisuje do zadaného zapisovače jednu hodnotu JSON (včetně objektů nebo polí).
public:
generic <typename TValue>
static void Serialize(System::Text::Json::Utf8JsonWriter ^ writer, TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static void Serialize<TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> unit
Public Sub Serialize(Of TValue) (writer As Utf8JsonWriter, value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue))
Parametry typu
- TValue
Typ hodnoty, která se má serializovat.
Parametry
- writer
- Utf8JsonWriter
Zapisovač, který se má psát.
- value
- TValue
Hodnota pro převod a zápis.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Metadata o typu, který chcete převést.
Výjimky
writer nebo jsonTypeInfo je null.
Pro serializovatelné členy není kompatibilní JsonConverterTValue .
Platí pro
Serialize<TValue>(Utf8JsonWriter, TValue, JsonSerializerOptions)
Zapíše reprezentaci JSON typu určeného parametrem obecného typu do zadaného zapisovače.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize<TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize<TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize<TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize<TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.Text.Json.Utf8JsonWriter * 'Value * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize(Of TValue) (writer As Utf8JsonWriter, value As TValue, Optional options As JsonSerializerOptions = Nothing)
Public Shared Sub Serialize(Of TValue) (writer As Utf8JsonWriter, value As TValue, Optional options As JsonSerializerOptions = Nothing)
Parametry typu
- TValue
Typ hodnoty, která se má serializovat.
Parametry
- writer
- Utf8JsonWriter
Zapisovatel JSON, do který se má zapisovat.
- value
- TValue
Hodnota pro převod a zápis.
- options
- JsonSerializerOptions
Možnosti řízení chování serializace
- Atributy
Výjimky
writer je null.
Pro serializovatelné členy není kompatibilní JsonConverterTValue .
Poznámky
Použitý JsonWriterOptions k vytvoření instance Utf8JsonWriter má přednost před konfliktem JsonSerializerOptions . Proto se JsonWriterOptions.IndentedJsonWriterOptions.SkipValidationpři psaní používají a JsonWriterOptions.Encoder používají se.
Další informace naleznete v tématu Jak serializovat a deserializovat JSON.
Platí pro
Serialize<TValue>(Stream, TValue, JsonTypeInfo<TValue>)
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru .
public:
generic <typename TValue>
static void Serialize(System::IO::Stream ^ utf8Json, TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> unit
Public Sub Serialize(Of TValue) (utf8Json As Stream, value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue))
Parametry typu
- TValue
Typ hodnoty, která se má serializovat.
Parametry
- value
- TValue
Hodnota, kterou chcete převést.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Metadata o typu, který chcete převést.
Výjimky
utf8Json je null.
Pro serializovatelné členy není kompatibilní JsonConverterTValue .
Platí pro
Serialize<TValue>(TValue, JsonSerializerOptions)
Převede hodnotu typu určeného parametrem obecného typu na řetězec JSON.
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static string Serialize<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static string Serialize<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static string Serialize<TValue>(TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static string Serialize<TValue>(TValue value, System.Text.Json.JsonSerializerOptions options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : 'Value * System.Text.Json.JsonSerializerOptions -> string
Public Function Serialize(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As String
Public Shared Function Serialize(Of TValue) (value As TValue, Optional options As JsonSerializerOptions = Nothing) As String
Parametry typu
- TValue
Typ hodnoty, která se má serializovat.
Parametry
- value
- TValue
Hodnota, kterou chcete převést.
- options
- JsonSerializerOptions
Možnosti řízení chování serializace
Návraty
Řetězcové vyjádření hodnoty VE FORMÁTU JSON.
- Atributy
Výjimky
Pro serializovatelné členy není kompatibilní JsonConverterTValue .
Poznámky
String Použití není tak efektivní jako použití kódování UTF-8, protože implementace interně používá UTF-8. Viz také SerializeToUtf8Bytes(Object, Type, JsonSerializerOptions) a SerializeAsync(Stream, Object, Type, JsonSerializerOptions, CancellationToken).
Další informace naleznete v tématu Jak serializovat a deserializovat JSON.
Platí pro
Serialize<TValue>(TValue, JsonTypeInfo<TValue>)
Převede zadanou Stringhodnotu na hodnotu .
public:
generic <typename TValue>
static System::String ^ Serialize(TValue value, System::Text::Json::Serialization::Metadata::JsonTypeInfo<TValue> ^ jsonTypeInfo);
public static string Serialize<TValue>(TValue value, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo);
static member Serialize : 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> -> string
Public Function Serialize(Of TValue) (value As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue)) As String
Parametry typu
- TValue
Typ hodnoty, která se má serializovat.
Parametry
- value
- TValue
Hodnota, kterou chcete převést.
- jsonTypeInfo
- JsonTypeInfo<TValue>
Metadata o typu, který chcete převést.
Návraty
Reprezentace String hodnoty.
Výjimky
Pro serializovatelné členy není kompatibilní JsonConverterTValue .
jsonTypeInfo je null.
Poznámky
String Použití není tak efektivní jako použití kódování UTF-8, protože implementace interně používá UTF-8. Viz také SerializeToUtf8Bytes<TValue>(TValue, JsonTypeInfo<TValue>) a SerializeAsync<TValue>(Stream, TValue, JsonTypeInfo<TValue>, CancellationToken).
Platí pro
Serialize<TValue>(Stream, TValue, JsonSerializerOptions)
Převede zadanou hodnotu na text JSON s kódováním UTF-8 a zapíše ho Streamdo souboru .
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
public static void Serialize<TValue>(System.IO.Stream utf8Json, TValue value, System.Text.Json.JsonSerializerOptions? options = default);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")>]
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions -> unit
static member Serialize : System.IO.Stream * 'Value * System.Text.Json.JsonSerializerOptions -> unit
Public Sub Serialize(Of TValue) (utf8Json As Stream, value As TValue, Optional options As JsonSerializerOptions = Nothing)
Parametry typu
- TValue
Typ hodnoty, která se má serializovat.
Parametry
- value
- TValue
Hodnota, kterou chcete převést.
- options
- JsonSerializerOptions
Možnosti pro řízení chování převodu
- Atributy
Výjimky
utf8Json je null.
Pro serializovatelné členy není kompatibilní JsonConverterTValue .