JSON Learning Notes

Source: Internet
Author: User

Definition: JSON is a JavaScript object notation.

Format:

var jsonobject ={

"url": "Www.baidu.com",

"Name": "Zkr",

"Address": "Shanghai"

}

Nested JSON multiple times:

var jsonobject={
"CH":
[
{"Names": "Yi Mei Homeland", "Data": [2,2,1,1,1,1], "Times": [10,11,13,13,21,23]},
{"Names": "Yi Mei Homeland", "Data": [2,2,1,1,1,1], "Times": [10,11,13,13,21,23]}
]
} ;

Basic syntax:

exists in the form of a value pair (name: value pair) key value;

If the value pair has multiple objects in the array [], each object is denoted by {}, and the key-value pairs are: separate;

Simple examples of use;

<script type= "Text/javascript" >
var jsono={
"Name": "Zkr",
"Age": 12,
"Hight": 165

"Adress": {
"China": "Guo",
"Jiangsu": "Sheng",
"Nanjing": "Shi"
}
}
Window.onload=function () {
document.getElementById ("name"). Innerhtml=jsono.name;
document.getElementById ("Age"). Innerhtml=jsono.age;
document.getElementById ("Hight"). Innerhtml=jsono.hight;

alert (JsonO.adress.china);
Alert (jsono.adress["Nanjing"]);
}

</script>

<div>
Name:<span id= "Name" ></span>
Age:<span id= "Age" ></span>
Hight:<span id= "Hight" ></span>
</div>

How to access JSON:

Through the form of., such as: Jsono.name;

In the form of ["name"],[array subscript], such as: jsono["name"], jsono["age"],jsono["hight"];

For nested JSON objects:

can use

JsonO.adress.china;
jsono.adress["Nanjing"];

Modifying the value of JSON

Jsono.adress.china= "Zhongguo";
jsono.adress["Nanjing"]= "Shenghui";

To delete an object's properties:

Delete keyword:

Delete JsonO.adress.china;

Delete jsono.adress["Nanjing"];

JSON Learning Notes

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.