C # using JSON

Source: Internet
Author: User

Ajax is the process of assembling and parsing a complex data that passes through its own format, so there is a de facto
Standard JSON for data transfer.
JSON serializes a complex object into a string, and then deserializes the string into an object that JavaScript can read in the browser side.
Look at the JSON format. JSON is supported in almost all languages.
C # will. NET object is serialized as a JSON string method:
JavaScriptSerializer (). Serialize (P), JavaScriptSerializer in System.Web.Extensions.dll,
is the new class in the. net3.x, if the. Third-party components are required in Net2.0.
JQuery Ajax gets data in JSON format, using the $.parsejson (data) method to parse JSON-formatted data into JavaScript objects
A function can pass "JSON" after the post function, and data is the object after deserialization, eliminating the Parsejson

Case: Returning a class to the client with JSON using the Jqurey
1. Processing page Settings Json1.ashx

public void ProcessRequest (HttpContext context)    {       context. Response.ContentType = "Text/plain";       JavaScriptSerializer JSS = new JavaScriptSerializer ();    Create JavaScriptSerializer       string  json = JSS. Serialize (new person () {name= "Xgao", age=18});       Context. Response.Write (JSON);    }    public class person    {public       string Name {get; set;}       public int Age {get; set;}    }

2.JAVAscript settings

    <script type= "Text/javascript" >        $ (function () {            $.post ("Json1.ashx", function (data, state) {                if (state = = "Success") {                    var person = $.parsejson (data);    Use Parsejson to convert                    alert (person. Name);                    Alert (person. (age)    ;}); </script>

C # using JSON

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.