Json.Encode Method

Converts a data object to a string that is in the JavaScript Object Notation (JSON) format.

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

public static string Encode(
	Object value


Type: System.Object
The data object to convert.

Return Value

Type: System.String
Returns a string of data converted to the JSON format.

Call the Encode method to convert a data object (for example, a set of data records that you return from a database query) to a string that is encoded in JSON format. You typically convert data objects to JSON format in order to work with the data as text in a web page by using JavaScript. This lets you create a page where users interact with the data in the browser without requiring round trips to the server.