Json
Alas, I finally wrote the JSON. Inexplicable happy, although still be said progress slow, but, I don't care, I am happy. Well, study hard and cheer up well. (This is a piece of logic, I don't know what to say)
JSON is a strict subset of JavaScript that uses some of the patterns in JavaScript to represent structured data. It is a data format, not a programming language.
Syntax
The JSON syntax supports simple values, objects, and arrays of three types of values. variables, functions, or object instances are not supported. It is the same as some of the syntax for representing data in JavaScript, but is not limited to the JavaScript category.
Simple values
Using the same syntax as JavaScript, you can represent strings, numeric values, Booleans, and Null in JSON. However, JSON does not support special value undefined in JavaScript.
The biggest difference between a JavaScript string and a JSON string is that the JSON string must use double quotation marks.
Object
Object as a complex data type that represents an unordered key-value pair. The value of each key-value pair can be a simple value or a complex value.
The JSON object does not declare a variable (the concept of a variable in JSON) compared to the object literal of JavaScript, and the second is a semicolon with no end. The value of the property can be either a simple value or a complex type value.
Array
is also a complex data type that represents a list of ordered values that can be accessed by a numeric index. The value of an array can also be any type-a simple value, an object, or an array.
The JSON array takes the form of an array literal in JavaScript. The JSON array also has no variables and semicolons. Combining arrays and objects can form a more complex set of data.
Objects and arrays are often the outermost form of JSON data structures that can be used to create a wide variety of data structures.
"Parsing and serialization"
JSON has a syntax similar to JavaScript, or it can parse JSON data structures into useful JavaScript objects.
JSON objects have both stringify () and Parse () methods. In the simplest case, these two methods are used to serialize JavaScript objects into JSON strings and to parse JSON strings into native JavaScript values. As follows
var book={ title:"Professional JavaScript", authors:[ "Nicholas C. Zakas" ], Edition:3, year : };var jaontext=json.stringify (book);
This example uses Json.stringify () to serialize a JavaScript object into a JSON string and then save it in the variable jsontext.
"Serialization Options"
Json.stringify () can receive two parameters, a parameter is a filter, can be an array, or it can be a function. The second parameter is an option that indicates whether indentation is preserved in the JSON string. These two parameters are used to specify that JavaScript objects are serialized in different ways.
Filter results
If the filter parameter is an array, then the result of Json.stringify () will contain only the attributes listed in the array.
To change the result of a serialized object, the value returned by the function is the value of the corresponding key. If the function returns undefined, then the corresponding property is ignored.
Each object in the object to be serialized is passed through a filter.
String indentation
The third parameter of the Json.stringify () method is used to control the indentation and whitespace characters in the result. If this parameter is a numeric value, it represents the number of spaces indented at each level. If the indent parameter is a string rather than a numeric value, the string is used as the indent character in the JSON string (no longer using spaces). The indent string cannot be longer than 10 characters long.
ToJSON () method
Suppose you pass an object into Json.stringify () and serialize the object in the following order
(1) if the Tojson () method is present and can be used to obtain a valid value, the method is called, otherwise, the object itself is returned.
(2) If the second parameter is provided, apply this function filter. The value of the filter passed in to the function is the value returned by step (1).
(3) The value returned by step (2) is serialized accordingly.
(4) If a third parameter is provided, the corresponding format is executed.
"Resolution Options"
The Json.parse () method can also receive another parameter, which is a function (the Restore function) that will be called on each key-value pair. If the Restore function returns undefined, it means to remove the corresponding key from the result. If another value is returned, the value is inserted into the result.
JavaScript (8)--json