The JSON method is only suitable for one object.
varP1 ={name:Mushrooms, Sex:Female, Dreamdu: {URL:"Www.dreamdu.com", Name:"The Dream Capital", Author:"Monkey", say:function() {document.write ( This. name+ "Say Hello")}//Allow nesting}, ShowName:function() {Console (' My name is ' + This. Name); }, Showsex:function() {Console.log (' My sex is ' + This. sex+ ' 's '); } }
- p1--JSON object name
- name--Property Name
- ShowName--Function name
Wrap the method in a JSON, called a namespace.
In the company, the same kind of method, wrapped together
These methods are organized in the form of packages, in the form of hierarchies. Ex
var maiov = {}; = { getbyclass:function () { }, myaddevent:function () { } } = { startmove:function () { }, drag:function () { } } // similar to the folder form Maiov.common.getByClass (); // so called, easy to manage.
Supplemental JSON
{"sites""name": "Rookie Tutorial", "url": "Www.runoob.com""name": "Google", "url": "Www.google.com" "name": "Weibo", "url": "Www.weibo.com" }]}
{key' key ': ' Value '/[' value ', ' value ', ' key ': ' Value '/[' value ', ' Value' key ': ' Value '/[' value ', ' value ', ' key ': ' Value '/[' value ', ' Value' key ":" Value "/[" value "," value "," Key ":" Value "/[" value "," Value "}]}
{} includes a set of key-value pairs that can be represented as "values" or [],
[] There can be several {}.
There are two kinds of structure of JSON structure
JSON is simply called objects and arrays in JavaScript, so these two structures are objects and arrays of two structures that can represent a variety of complex structures.
1. Object: The object in JS is represented as "{}" in the content, the data structure is {Key:value,key:value,...} The structure of key-value pairs, in object-oriented languages, key is the property of the object, value is the corresponding property value, so it is easy to understand that the value method is the object. Key Gets the property value, the type of the property value can be a number, a string, an array, several objects.
2, array: The array in JS is the middle bracket "[]" in the content, data structure for ["Java", "JavaScript", "VB",...], the value way and all languages, using index get, the type of field value can be number, string, array, object several.
Through the object, the array 2 kinds of structure can be combined into a complex data structure.
Object-oriented JSON method