Explore the message transfer mode in asp.net ajax (II.)

Source: Internet
Author: User

In the previous article, "Exploring the message transfer model in AJAX (i)", I mainly introduced the common string (Plain-text string) and the XML format transmission mode, however, in practical development applications, these two methods are basically enough to meet our needs, However, in the case of complex objects, the two transmission modes described above are somewhat unsatisfactory. In this context, this article will combine the "explore the message transfer model in Ajax" (a) to introduce a lightweight data Interchange Format JSON (JavaScript object notation), which is a javascrpt of its own to describe the object of the method, JSON can be said to be an alternative to XML from a certain point of view.

Before using JSON for data transfer, let's look at a few simple JSON syntaxes to lay the groundwork for friends who are unfamiliar with JSON and want to see this article. JSON is a simple text format as well as XML. Compared with XML, it is more readable and easier to inspect. On the grammatical level, the difference between JSON and other formats is the character that separates the data, and the delimiters in JSON are limited to single quotes, parentheses, brackets, braces, colons, and commas. The following is a JSON payload:

{"UserID":"0001","UserName":"ZhangSan","UserAge":"22"}

Looks like it's not very simple, the key is corresponding to the value one by one (key----value), let's look at the JSON payload for a complex point:

1{Employees:[
2    {"EmployeeID":"1","LastName":"Davolio","City":"Seattle","Country":"USA"},
3    {"EmployeeID":"2","LastName":"Fuller","City":"Tacoma","Country":"USA"}
4      ]
5}

It is clear from the JSON above that there are two of data in the Employees object, which we rewrite with XML as follows:

1<?xml version='1.0' ?>
2<Employees>
3 <Employee>
4   <EmployeeID>1</EmployeeID>
5   <LastName>Davolio</LastName>
6   <City>Seattle</City>
7   <Country>USA</Country>
8 </Employee>
9 <Employee>
10  <EmployeeID>2</EmployeeID>
11  <LastName>Fuller</LastName>
12  <City>Tacoma</City>
13  <Country>USA</Country>
14 </Employee>
15<Employees>

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.