Json.parse () and Json.stringify ()

Source: Internet
Author: User

The 
 json.parse () method is used to parse a JSON string, constructing a JavaScript value or object that is described by a string. An optional Reviver function is provided to perform transformations (operations) on the resulting object before returning. Syntax Json.parse (text[, reviver]) parameter text the string to be parsed into JavaScript values to see a description of the JSON syntax for JSON object learning. Reviver Optional If it is a function, it specifies how the original value is parsed and transformed before it is returned. The return value object corresponds to the given JSON text. Exception if the parsed JSON string is illegal, a syntax error exception is thrown.              The example uses Json.parse () Json.parse ( ' {} '); //             {}  json.parse (' true '); //  true            Json.parse (' "foo"); //  "foo"  Json.parse (' [1, 5, ' false '] '); //  [1, 5, "false"]             Json.parse (' null '); //  null  
The Json.stringify () method converts a JavaScript value (object or array) to a JSON string, and if Replacer is specified as a function, the value can be substituted, or if replacer is specified as an array, Optional includes only the specified properties. The syntax json.stringify (value[, Replacer [, Space]]) parameter    value will be serialized into a JSON string. Replacer Optional    If the parameter is a function, each property of the serialized value is transformed and processed by the function during serialization, and if the parameter is an array, only the name of the property contained in the array is serialized into the final JSON string;
If the parameter is null or not provided, all properties of the object are serialized, and for more detailed explanations and examples of this parameter, refer to the article using native JSON objects. Space optionally specifies a blank string for indentation, which is used to beautify the output (pretty
-print), and if the argument is a number, it represents how many spaces it has; the upper limit is 10. A value less than 1 means there is no space, and if the argument is a string (the first 10 letters of the string), the string is used as a space, and if the argument is not provided (or null), there will be no spaces. The return value is a JSON string that represents the given value.

Json.parse () and Json.stringify ()

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.