About the. NET MVC4 Action method returns the difference between Jsonresult and the return string type

Source: Internet
Author: User

First, the conclusion: Set returns a string of type Response.ContentType = "Application/json"; equals the use of Jsonresult.   Evidence 1: Set to return a string of type Response.ContentType = "Application/json". JQ automatically converts the JSON string to a JSON object. If  response.contenttype = "Application/json" is not set, the default value Response.ContentType = "text/html" is used. This way, JQ does not convert the JSON string to a JSON object. Look at the following two examples:----------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -----------------  Evidence 2: Set jsonresult  ContentType = "text/html" so that JQ does not convert the JSON string to a JSON object. Conversely, using the default value is ContentType = "application/json ", and JQ automatically converts the JSON string to a JSON object. Look at the following two examples:----------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------  The evidence above proves my conclusion. Here are the points: 1. When the JSON data returned to the front end is not standard such as-"{\" age\ ": \" fdasfdasf\ ", \" name\ ": \" Rer\ "}", the value of the front-end grab is the same as I gave. Whether you use Jsonresult and the return string type, you need to manually  json.parse (Data) to change the string to a JSON object. 1. When returning to the front-end JSON data, the standard is such as-"{" "Age": "fdasfdasf", "Name": "RER"} ", the value of the front-end grab is the same as I gave." Just make sure that the ContentType = "APPLICATION/JSON,JQ of the response header will automatically convert the JSON string to a JSON object.  2014.09.02   Liu Yan   in Guangzhou

about the. NET MVC4 Action method returns Jsonresult and returns the difference between string types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.