Controller.Json Method

 

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.

Namespace:   System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Overload List

Name Description
System_CAPS_protmethod Json(Object)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON).

System_CAPS_protmethod Json(Object, JsonRequestBehavior)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified JSON request behavior.

System_CAPS_protmethod Json(Object, String)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.

System_CAPS_protmethod Json(Object, String, Encoding)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.

System_CAPS_protmethod Json(Object, String, Encoding, JsonRequestBehavior)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the content type, content encoding, and the JSON request behavior.

System_CAPS_protmethod Json(Object, String, JsonRequestBehavior)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified content type and JSON request behavior.

See Also

Controller Class
System.Web.Mvc Namespace

Return to top

Controller.Json Method (Object)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON).

Syntax

protected internal JsonResult Json(
    object data
)
public protected:
JsonResult^ Json(
    Object^ data
)
member Json : 
        data:Object -> JsonResult
Protected Friend Function Json (
    data As Object
) As JsonResult

Parameters

  • data
    Type: System.Object

    The JavaScript object graph to serialize.

Return Value

Type: System.Web.Mvc.JsonResult

The JSON result object that serializes the specified object to JSON format. The result object that is prepared by this method is written to the response by the ASP.NET MVC framework when the object is executed.

Return to top

Controller.Json Method (Object, JsonRequestBehavior)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified JSON request behavior.

Syntax

protected internal JsonResult Json(
    object data,
    JsonRequestBehavior behavior
)
public protected:
JsonResult^ Json(
    Object^ data,
    JsonRequestBehavior behavior
)
member Json : 
        data:Object *
        behavior:JsonRequestBehavior -> JsonResult
Protected Friend Function Json (
    data As Object,
    behavior As JsonRequestBehavior
) As JsonResult

Parameters

  • data
    Type: System.Object

    The JavaScript object graph to serialize.

Return Value

Type: System.Web.Mvc.JsonResult

The result object that serializes the specified object to JSON format.

Remarks

The data in the data parameter must be serializable. The JavaScriptSerializer class is used to serialize the object. The result object that is prepared by this method is written to the response by the ASP.NET MVC framework when the object is executed.

Return to top

Controller.Json Method (Object, String)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.

Syntax

protected internal JsonResult Json(
    object data,
    string contentType
)
public protected:
JsonResult^ Json(
    Object^ data,
    String^ contentType
)
member Json : 
        data:Object *
        contentType:string -> JsonResult
Protected Friend Function Json (
    data As Object,
    contentType As String
) As JsonResult

Parameters

  • data
    Type: System.Object

    The JavaScript object graph to serialize.

Return Value

Type: System.Web.Mvc.JsonResult

The JSON result object that serializes the specified object to JSON format.

Remarks

The data parameter must be serializable. The JavaScriptSerializer class is used to serialize the object. The result object that is prepared by this method is written to the response by the ASP.NET MVC framework when the object is executed.

Return to top

Controller.Json Method (Object, String, Encoding)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.

Syntax

protected internal virtual JsonResult Json(
    object data,
    string contentType,
    Encoding contentEncoding
)
public protected:
virtual JsonResult^ Json(
    Object^ data,
    String^ contentType,
    Encoding^ contentEncoding
)
abstract Json : 
        data:Object *
        contentType:string *
        contentEncoding:Encoding -> JsonResult
override Json : 
        data:Object *
        contentType:string *
        contentEncoding:Encoding -> JsonResult
Protected Friend Overridable Function Json (
    data As Object,
    contentType As String,
    contentEncoding As Encoding
) As JsonResult

Parameters

  • data
    Type: System.Object

    The JavaScript object graph to serialize.

Return Value

Type: System.Web.Mvc.JsonResult

The JSON result object that serializes the specified object to JSON format.

Remarks

The data parameter must be serializable. The JavaScriptSerializer class is used to serialize the object. The result object that is prepared by this method is written to the response by the ASP.NET MVC framework when the object is executed.

Return to top

Controller.Json Method (Object, String, Encoding, JsonRequestBehavior)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the content type, content encoding, and the JSON request behavior.

Syntax

protected internal virtual JsonResult Json(
    object data,
    string contentType,
    Encoding contentEncoding,
    JsonRequestBehavior behavior
)
public protected:
virtual JsonResult^ Json(
    Object^ data,
    String^ contentType,
    Encoding^ contentEncoding,
    JsonRequestBehavior behavior
)
abstract Json : 
        data:Object *
        contentType:string *
        contentEncoding:Encoding *
        behavior:JsonRequestBehavior -> JsonResult
override Json : 
        data:Object *
        contentType:string *
        contentEncoding:Encoding *
        behavior:JsonRequestBehavior -> JsonResult
Protected Friend Overridable Function Json (
    data As Object,
    contentType As String,
    contentEncoding As Encoding,
    behavior As JsonRequestBehavior
) As JsonResult

Parameters

  • data
    Type: System.Object

    The JavaScript object graph to serialize.

Return Value

Type: System.Web.Mvc.JsonResult

The result object that serializes the specified object to JSON format.

Remarks

The data in the data parameter must be serializable. The JavaScriptSerializer class is used to serialize the object. The result object that is prepared by this method is written to the response by the ASP.NET MVC framework when the object is executed.

Return to top

Controller.Json Method (Object, String, JsonRequestBehavior)

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified content type and JSON request behavior.

Syntax

protected internal JsonResult Json(
    object data,
    string contentType,
    JsonRequestBehavior behavior
)
public protected:
JsonResult^ Json(
    Object^ data,
    String^ contentType,
    JsonRequestBehavior behavior
)
member Json : 
        data:Object *
        contentType:string *
        behavior:JsonRequestBehavior -> JsonResult
Protected Friend Function Json (
    data As Object,
    contentType As String,
    behavior As JsonRequestBehavior
) As JsonResult

Parameters

  • data
    Type: System.Object

    The JavaScript object graph to serialize.

Return Value

Type: System.Web.Mvc.JsonResult

The result object that serializes the specified object to JSON format.

Remarks

The data in the data parameter must be serializable. The JavaScriptSerializer class is used to serialize the object. The result object that is prepared by this method is written to the response by the ASP.NET MVC framework when the object is executed.

Return to top