Json first-time experience-understand what is the role of json and json, And the json syntax format

Source: Internet
Author: User

Json first-time experience-understand what is the role of json and json, And the json syntax format

I watched a video about json today. The following are my study notes:

1. What is json?

Json is a [Special] MARK [String] written in [JavaScript syntax ].

2. Functions of json

(A) Simplified the way to define objects using JavaScript
(B) It can also be used in AJAX as one of the data carriers.

3. Functions of json syntax

(A) An object is represented {}
(B) One pair of attributes are separated by:. After the attribute ends, use, to separate the last one.
(C) An Array Using the [] symbol


The following is the html code defined in this document.

 Insert title here<Script type = "text/javascript"> // The General javascript definition object document. write ("General javascript definition object -----------"); function Student (id, name, sex) {this. id = id; this. name = name; this. sex = sex ;}; var s = new Student (12, "wang", "nan"); document. write (s. id +"
"); Document. write (s. name +"
"); Document. write (s. sex +"
"); // Use json to define a simple document. write ("defined in json format, more simple -----------"); var B = {id: 13, name: "zhang", sex: "nan"}; document. write (B. id +"
"); Document. write (B. name +"
"); Document. write (B. sex +"
"); // It is defined in json format, including the array document. write ("defined in json format, including arrays -----------"); var bs = [{id: 14, name: "zhang14", sex: "nan15"}, {id: 15, name: "zhang15", sex: "nan15"}] for (var I = 0; I "); Document. write (bs [I]. name +"
"); Document. write (bs [I]. sex +"
");} // It is defined in json format. The object attributes include the array document. write ("defined in json format, Object Attributes contain arrays -----------"); var p = {citys: ['guangzhou ', 'zhongshan', 'foshan ', 'shenzhen ']}; for (var I = 0; I ");} // It is defined in json format. The object attributes include the array document. write ("defined in json format, object attributes include arrays, and array objects have attributes -----------"); var p = {id: 16, name: "tai ", salary: 6000, citys: [{id: 1, name: "Guangzhou" },{ id: 2, name: "Changsha"}]}; document. write ("No.:" + p. id +"
"); Document. write (" name: "+ p. name +"
"); Document. write (" salary: "+ p. salary +"
"); Document. write (" has been to the following cities:
"); For (var I = 0; I ");} // It is defined in json format. The object attributes include the array document. write ("defined in json format, the object attributes contain internal functions (the function is an unknown function) -----------"); var ac = {id: 17, name: "li ", show: function (msg) {// internal function to access external function, // you need to use the object. attribute method access. // otherwise, the blank string alert ("Your name is -->" + p. name); alert (msg) ;}}; ac. show ("test internal function"); </script>

The following is the result of the html code:

General javascript definition object ----------- 12
Wang
Nan
It is simpler to define in json format ----------- 13
Zhang
Nan
Use json to define, including arrays ----------- 14
Zhang14
Nan15
15
Zhang15
Nan15
It is defined in json format. The object attributes contain arrays ----------- Guangzhou
Zhongshan
Foshan
Shenzhen
It is defined in json format. attributes of an object include arrays, and attributes ----------- ID: 16 exist in the array object.
Name: tai
Salary: 6000
You have visited the following cities:
Guangzhou
Changsha
It is defined in json format. The object attributes contain internal functions (the function is an unknown function )-----------


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.