Share via


TypedResults.Json 方法

定義

多載

Json<TValue>(TValue, JsonSerializerOptions, String, Nullable<Int32>)

建立 , JsonHttpResult<TValue> 將指定的 data 物件序列化為 JSON。

Json<TValue>(TValue, JsonSerializerContext, String, Nullable<Int32>)

建立 , JsonHttpResult<TValue> 將指定的 data 物件序列化為 JSON。

Json<TValue>(TValue, JsonTypeInfo<TValue>, String, Nullable<Int32>)

建立 , JsonHttpResult<TValue> 將指定的 data 物件序列化為 JSON。

Json<TValue>(TValue, JsonSerializerOptions, String, Nullable<Int32>)

建立 , JsonHttpResult<TValue> 將指定的 data 物件序列化為 JSON。

public static Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<TValue> Json<TValue> (TValue? data, System.Text.Json.JsonSerializerOptions? options = default, string? contentType = default, int? statusCode = default);
static member Json : 'Value * System.Text.Json.JsonSerializerOptions * string * Nullable<int> -> Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<'Value>
Public Shared Function Json(Of TValue) (data As TValue, Optional options As JsonSerializerOptions = Nothing, Optional contentType As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing) As JsonHttpResult(Of TValue)

類型參數

TValue

將 JSON 序列化至回應本文的物件類型。

參數

data
TValue

要寫入為 JSON 的物件。

options
JsonSerializerOptions

序列化值時要使用的序列化程式選項。

contentType
String

回應上要設定的內容類型。

statusCode
Nullable<Int32>

回應上要設定的狀態碼。

傳回

建立 JsonHttpResult<TValue> 的 ,會將指定的 data 序列化為回應的 JSON 格式。

備註

呼叫端應該快取序列化程式設定的實例,以避免在每個呼叫中重新建立快取的資料。

適用於

Json<TValue>(TValue, JsonSerializerContext, String, Nullable<Int32>)

建立 , JsonHttpResult<TValue> 將指定的 data 物件序列化為 JSON。

public static Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<TValue> Json<TValue> (TValue? data, System.Text.Json.Serialization.JsonSerializerContext context, string? contentType = default, int? statusCode = default);
static member Json : 'Value * System.Text.Json.Serialization.JsonSerializerContext * string * Nullable<int> -> Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<'Value>
Public Shared Function Json(Of TValue) (data As TValue, context As JsonSerializerContext, Optional contentType As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing) As JsonHttpResult(Of TValue)

類型參數

TValue

將 JSON 序列化至回應本文的物件類型。

參數

data
TValue

要寫入為 JSON 的物件。

context
JsonSerializerContext

可序列化類型的中繼資料提供者。

contentType
String

回應上要設定的內容類型。

statusCode
Nullable<Int32>

回應上要設定的狀態碼。

傳回

建立 JsonHttpResult<TValue> 的 ,會將指定的 data 序列化為回應的 JSON 格式。

適用於

Json<TValue>(TValue, JsonTypeInfo<TValue>, String, Nullable<Int32>)

建立 , JsonHttpResult<TValue> 將指定的 data 物件序列化為 JSON。

public static Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<TValue> Json<TValue> (TValue? data, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo, string? contentType = default, int? statusCode = default);
static member Json : 'Value * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'Value> * string * Nullable<int> -> Microsoft.AspNetCore.Http.HttpResults.JsonHttpResult<'Value>
Public Shared Function Json(Of TValue) (data As TValue, jsonTypeInfo As JsonTypeInfo(Of TValue), Optional contentType As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing) As JsonHttpResult(Of TValue)

類型參數

TValue

將 JSON 序列化至回應本文的物件類型。

參數

data
TValue

要寫入為 JSON 的物件。

jsonTypeInfo
JsonTypeInfo<TValue>

要轉換之型別的相關中繼資料。

contentType
String

回應上要設定的內容類型。

statusCode
Nullable<Int32>

回應上要設定的狀態碼。

傳回

建立 JsonHttpResult<TValue> 的 ,會將指定的 data 序列化為回應的 JSON 格式。

適用於