JavaScript data-related processing, serialization deserialization, data encoding and decoding

Source: Internet
Author: User

Object serialization in short, the object is converted to a string. In the process of data transmission, object serialization is often used.

Serialization of objects commonly used in javascript: Json.stringify ();

Deserialization of objects commonly used in javascript: Json.parse ();

Note: json.stringify compatible IE8+,IE7 as well as the available json2.js, the corresponding resources can be downloaded online

var a = {"name": "Mary", "Age": "100"}   
var B = json.stringify (a); The resulting data ' {' name ': ' Mary ', ' age ': ' + '   to turn data into a string

var C = json.parse (b); The resulting data {"name": "Mary", "Age": "100"} will restore the data to its original object form

JS to encode the text involves 3 functions: Escape,encodeuri,encodeuricomponent, the corresponding 3 decoding function: unescape,decodeuri,decodeuricomponent

Escape escapes the string, which is generally not commonly used, and it escapes escape () to encode all incoming strings except ASCII letters, numbers, and specific symbols.

encodeURI encodes a string as a URI, which is generally used to encode the entire URI, because the legitimate characters in the URI are not encoded for conversion.

encodeURIComponent encodes the string as a URI component. The encoded data default parameter is part of a URI (such as a protocol, host name, path, or query string). Instead, encodeURI encodes the entire URI.

JavaScript data-related processing, serialization deserialization, data encoding and decoding

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.