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 格式。

适用于