Represents a class that is used to send JSON-formatted content to a response.
ContentEncoding: Encoding format (preferably by standard utf-8)
Contenttype:mime type
Data: Settings
Jsonrequestbehavior: The request type that indicates whether to allow HTTP GET requests from the client, enumerate
Maxjsonlength: Gets or sets the maximum length of the data.
Recursionlimit: Gets or sets the recursion limit
This article hierarchy of the painting is very good (original: http://www.cnblogs.com/celery94/archive/2011/01/12/1933541.html)
This class is actually a class that MVC uses for our packaged server-side interaction with JSON and the client, and we tend not to use that class directly, but the controller provides a more streamlined operation class.
Okay, just look at the latter method.
Protected internal virtual Jsonresult Json (object data, String ContentType, Encoding contentencoding, Jsonrequestbehavior behavior)
{
return new Jsonresult {data = data, ContentType = ContentType, contentencoding = contentencoding, Jsonrequestbehavior = b Ehavior};
}
In fact, the method is very simple, directly created a Jsonresult object returned.
Then look at the properties of the Jsonresult.data, object type. Why is JSON information a string type?
In conjunction with the usual use, it is easy to guess, not just to use the object initializer to create a JSON object.
Object initializer, in fact, a bold guess, the object initialization of what, it is generally possible to think, it must be the compiler or VS and the like for us to create such objects, but is done internally. Just like anonymous functions, because the name is automatically generated, we do not know, can only be used once, so call it anonymous. In essence, when our code is compiled, the generated IL is definitely the same, but it's a simple way (syntax sugar) that the compiler provides for us.
From the above figure we can clearly understand that MS for our action provides a series of return types, convenient for us to use, from the jsonresult we can see, for us to simplify a lot of things, do not need us to splice JSON string and so on, to avoid a lot of errors, We believe that the efficiency of the package will be much higher than our own writing. Here is an article on each of the return type examples, small partners can see, it is not difficult. The return type of the action will be used in the ActionResult provided in MVC. (Follow MVC's standards, habits)
(Original: http://www.cnblogs.com/key1309/p/3480617.html)
(About object initializers Artech A good article, very deep : http://www.cnblogs.com/artech/archive/2007/09/30/912166.html)
(Here's an article on the action return Jsonresult test: http://www.cnblogs.com/JustRun1983/p/3251426.html)