JSON is a data format. JSON does not belong to JavaScript. Also, JSON is not only used by JavaScript, after all, JSON is just a data format. Many programming languages have parsers and serializers for JSON. JSON consists of three types, simple, object, and array. Simple values include numeric value, String, Boolean, null. An object consists of a set of key-value pairs that can nest arrays and objects. An array represents an ordered set of worthwhile lists that can contain arrays and objects.
Console.log (Json.parse (1)); Console.log (Json.stringify (1));
This is not wrong to write, can directly parse the value, but this does not make sense, the general application of the JSON is in the form of objects or arrays presented. Here's a look at the object's notation:
{ "name""oldlee", " Age " - } [1,2,"ac"]
JSON objects and arrays are similar to JavaScript object literals and array literals, and all keys in the JSON are wrapped in double quotes, otherwise they can cause syntax errors. The value of the string must also be wrapped in double quotes, not single quotes, because it can cause syntax errors, as well as in arrays. In JSON, an object can contain an array, and the same array can contain objects.
{ "name":"Oldlee", " Age": -, "Skills": ["Anglurjs","ES6","HTML5","CSS3"], "Friends" : [ { "name":"King", " Age": - }, { "name":"Wang", " Age": - } ]}
Json.parse;
Function: Converts a JSON string of JavaScript Object notation to an object (string to object)
Syntax: Json.parse (text [, Reviver])
Text must be selected. A valid JSON string.
Reviver is optional. A function that transforms the result. This function is called for each member of the object.
Return value: JSON object
Json.stringify
Role: A JSON string that converts a JavaScript JSON object to a JavaScript Object notation (object to String)
Syntax: json.stringify (value [, Replacer] [, space]);
Value required is typically an object or an array
Replacer function or array with optional conversion result
Space is optional. Adding indents, whitespace, and newline characters returns the value of the JSON text for easier reading.
If space is omitted, the return value text is generated without any additional whitespace.
If space is a number, the return value has a blank text indent for the specified number at each level. If space is greater than 10 o'clock, the text indents 10 blanks.
If space is a non-empty string, such as "\ T", the return value text is indented with the character of the string at each level.
If space is a string greater than 10 characters, the first 10 characters are used.
Return value: The text string that the JSON contains.
JS JSON format operation