Front-end Basics about JSON

Source: Internet
Author: User

JSON (JavaScript Object Notation) is a lightweight data interchange format. Easy for people to read and write. It is also easy for machine parsing and generation. It is based on JavaScript programming Language, Standard ECMA-262 a subset of 3rd Edition-december 1999. JSON takes a completely language-independent text format, but also uses a similar idiom to the C language family (c, C + +, C #, Java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language.

JSON is constructed in two structures:

A collection of name/value pairs (A collection of name/value pairs). In different languages, it is understood as objects (object), record (record), structure (struct), Dictionary (dictionary), hash table (hash table), keyed list (keyed list), or associative array (associative Array).
The sequence of values (an ordered list of values). In most languages, it is understood as an array (array).

--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------
json.stringify function (JavaScript)

Converts the JavaScript value to a JavaScript Object notation (Json) string. Return value: A string containing the JSON text.

Json.stringify (value [, Replacer] [, space])

Value
Necessary. The JavaScript value to convert (typically an object or an array).

Replacer
Optional. The function or array used to convert the result.

If Replacer is a function, Json.stringify calls the function and passes in the key and value of each member. Use the return value instead of the original value. If this function returns undefined, the member is excluded. The key of the root object is an empty string: "".

If Replacer is an array, only the members with key values in the array are converted. The members are converted in the same order as the keys in the array. When the value parameter is also an array, replacer arrays are ignored.

Space
Optional. Adds indents, spaces, and line breaks to the return value JSON text to make it easier to read.

If space is omitted, the return value text is generated, without any space cells.

If space is a number, the return value text indents the specified number of spaces at each level. If space is greater than 10, the text indents 10 spaces.

If space is a non-empty string (for example, "\ T"), the return value text indents the characters in the string at each level.

If space is a string longer than 10 characters, the first 10 characters are used.

Json.parse function (JavaScript)

Converts a JavaScript object notation (JSON) string to an object. Return value: An object or an array.

Json.parse (text [, Reviver])
Parameters
Text
Necessary. A valid JSON string.

Reviver
Optional. A function that transforms the result. This function is called for each member of the object. If the member contains nested objects, the nested objects are converted before the parent object. For each member, the following conditions occur:

If Reviver returns a valid value, the member value is replaced with the converted value.

If Reviver returns the same value it receives, the member value is not modified.

If reviver returns null or undefined, the member is deleted.

Front-end Basics about JSON

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.