Controller.Json Method

Definition

Overloads

Json(Object)

Creates a JsonResult object that serializes the specified data object to JSON.

Json(Object, JsonSerializerSettings)

Creates a JsonResult object that serializes the specified data object to JSON.

Json(Object, Object)

Creates a JsonResult object that serializes the specified data object to JSON.

Json(Object)

Creates a JsonResult object that serializes the specified data object to JSON.

public:
 virtual Microsoft::AspNetCore::Mvc::JsonResult ^ Json(System::Object ^ data);
[Microsoft.AspNetCore.Mvc.NonAction]
public virtual Microsoft.AspNetCore.Mvc.JsonResult Json (object data);
abstract member Json : obj -> Microsoft.AspNetCore.Mvc.JsonResult
override this.Json : obj -> Microsoft.AspNetCore.Mvc.JsonResult
Public Overridable Function Json (data As Object) As JsonResult

Parameters

data
Object

The object to serialize.

Returns

JsonResult

The created JsonResult that serializes the specified data to JSON format for the response.

Attributes

Json(Object, JsonSerializerSettings)

Creates a JsonResult object that serializes the specified data object to JSON.

public:
 virtual Microsoft::AspNetCore::Mvc::JsonResult ^ Json(System::Object ^ data, Newtonsoft::Json::JsonSerializerSettings ^ serializerSettings);
[Microsoft.AspNetCore.Mvc.NonAction]
public virtual Microsoft.AspNetCore.Mvc.JsonResult Json (object data, Newtonsoft.Json.JsonSerializerSettings serializerSettings);
abstract member Json : obj * Newtonsoft.Json.JsonSerializerSettings -> Microsoft.AspNetCore.Mvc.JsonResult
override this.Json : obj * Newtonsoft.Json.JsonSerializerSettings -> Microsoft.AspNetCore.Mvc.JsonResult
Public Overridable Function Json (data As Object, serializerSettings As JsonSerializerSettings) As JsonResult

Parameters

data
Object

The object to serialize.

serializerSettings
Newtonsoft.Json.JsonSerializerSettings

The Newtonsoft.Json.JsonSerializerSettings to be used by the formatter.

Returns

JsonResult

The created JsonResult that serializes the specified data as JSON format for the response.

Attributes

Remarks

Callers should cache an instance of Newtonsoft.Json.JsonSerializerSettings to avoid recreating cached data with each call.

Json(Object, Object)

Creates a JsonResult object that serializes the specified data object to JSON.

public:
 virtual Microsoft::AspNetCore::Mvc::JsonResult ^ Json(System::Object ^ data, System::Object ^ serializerSettings);
[Microsoft.AspNetCore.Mvc.NonAction]
public virtual Microsoft.AspNetCore.Mvc.JsonResult Json (object data, object serializerSettings);
abstract member Json : obj * obj -> Microsoft.AspNetCore.Mvc.JsonResult
override this.Json : obj * obj -> Microsoft.AspNetCore.Mvc.JsonResult
Public Overridable Function Json (data As Object, serializerSettings As Object) As JsonResult

Parameters

data
Object

The object to serialize.

serializerSettings
Object

The serializer settings to be used by the formatter.

When using System.Text.Json, this should be an instance of JsonSerializerOptions.

When using Newtonsoft.Json, this should be an instance of JsonSerializerSettings.

Returns

JsonResult

The created JsonResult that serializes the specified data as JSON format for the response.

Attributes

Remarks

Callers should cache an instance of serializer settings to avoid

        recreating cached data with each call.

Applies to