Josn Learning Summary < two > JSON format and syntax

Source: Internet
Author: User

It's early tonight!! Hey, continue josn summary!!!! Some people say so simple still need to write??? I think "10 times in the eye than in the hand"!! Please correct me if there is a mistake!! Learn together!!! Nonsense not to say, into the subject of tonight:

< two > JSON format and Syntax:

JavaScript makes it very easy to create and access JSON objects with the following syntax:

1 var jsonobject=2    {3        PropertyName (attribute name): value (value),//  property syntax within an object (property name and property value are paired)4        functionname (function name): Fucntion () {...} // function syntax within an object (the function name is paired with its contents) 5     };

For the above syntax, here's the analysis:

1), Jsonobject:json object name

2), PropertyName: attribute name

3), functionname: function name

4), a pair of curly braces, enclosing multiple "name/value" collections

JSON is represented by a collection of "name/value" or "key/value" pairs, or it can be understood as an array, where the property name or function name can be any string (but must be meaningful, recognizable), or even an empty string.

Commas are used to split each pair of "name/value" pairs, in the simplest form, as shown in the following JSON:

1 {"Fistname":"aju"}

This is a very basic example, and actually takes up more space than the equivalent plain text name/value pair ( Firstname=aju ).

However, when multiple name/value pairs are strung together, the value of the JSON is reflected, and the following is a record that contains multiple name/value pairs:

 1  {"Firstname"  Span style= "Color:rgb (128, 0, 0); >:   zhang " "  lastname Span style= "Color:rgb (128, 0, 0); >:   aju "  email "  " 1022560838  @ Qq.com };  

Syntactically, this has no significant advantage over name/value pairs, but in this case, JSON is easier to use and more readable, for example: it explicitly indicates that the above three values are one of the same records

The curly braces cause these values to have some kind of connection.

When you need to represent a set of values, josn not only improves readability, but also reduces complexity, such as: if you want to represent a list of people, in XML, you need many start and end tags;

A typical name/value pair, then a proprietary data format must be established. If you use JSON, you only need to group multiple records with curly braces together:

1 {2      "people":[3{"FirstName":"Zhao","LastName":"Liang","Email":"[email protected]"},4{"FirstName":"Zhang","LastName":"Liang","Email":"[email protected]"},5{"FirstName":"Li","LastName":"Si","Email":"[email protected]"}6]}

This should not be difficult to understand, this example, only a variable named people, the value is a three array, each array is a person's record, including first name, last name, e-mail, the above example shows how to use the

Number to combine records into a single value, of course, you can use the same syntax to represent multiple values (each value contains multiple records):

1 {2    "Programmers":[3{"FirstName":"Zhang","Lsatname":"San"},4{"FirstName":"Li","Lsatname":"Si"}5           ],6    "authors":[7{"FirstName":"Wang","Lsatname":"Wu"},8{"FirstName":"Lu","Lsatname":"Liu"}9          ],Ten    "musicians":[ One{"FirstName":"Qi","Lsatname":"Qiang"}, A{"FirstName":"Huang","Lsatname":"San"} - ] -}

It is worth noting that it is possible to represent multiple values, each containing multiple values, but it should also be noted that in different arrays ("Programmenrs", "authors", "musicians"), the actual

Name/value pairs, which can be different, JSON is completely dynamic (you can write as long as it conforms to its syntax specification)

When working with JSON-formatted data, there is no need to adhere to the predefined constraints, so in the same data structure, you can change the way the data is represented;

I'll write it here tonight, eat,girl friend has been called several times, if tomorrow night work early, ready to write a third: JavaScript processing 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.