basic usage of 1.stringify functions
The purpose of the Stringify function is to serialize the object, that is, to convert the object type to a string type (the default delimiter ("&") and the quantifier ("="), and this section first describes its basic usage, and in the next section we will learn how to replace the default Let's take a look at the following examples to understand clearly!
Example 1:querystring.stringify ("Object")
- var querystring= require(' querystring ');
- var result = querystring. Stringify({foo:' Bar ',cool: [' Xux ', ' Yys ']});
- Console. Log(result);
Operation Result:
- Foo=bar&Cool=xux&Cool=yys
Multi-parameter usage of 2.stringify functions
In this section we will learn the multi-parameter usage of the Stringify function, the last section we know that the object is serialized as a string after the default is by the delimiter ("&") and the allocation ("=") of the composition, that can be changed, this section we come to understand, whether you could define the combination of the results, Look at the following small example
Example 1:querystring.stringify ("Object", "delimiter", "quantifier")
- var querystring = require(' querystring ');
- var result = querystring. Stringify({foo:' Bar ',cool: [' Xux ', ' Yys ']},' * ' ,' $ ');
- Console. Log(result);
Operation Result:
- ' Foo$bar*cool$xux*cool$yys '
basic usage of 3.parse functions
We have just learned the role of the Stringify function, and then we will learn the--parse function of the deserialization function, the function of the parse function is to deserialize the string (by default, "=", "&" stitching), the conversion to get an object type. The following example:
Example 1:querystring.parse ("string")
- var querystring = require(' querystring ');
- var result = querystring. Parse(' Foo=bar&cool=xux&cool=yys ');
- Console. Log(result);
Operation Result:
- { foo: ' Bar ', cool: [' Xux ', ' Yys ']}
Multi-parameter usage of 4.parse functions
Now that we are learning the extended use of the parse function, unlike the multi-parameter usage of the Stringify function in the previous section, the parse function can deserialize the string according to the user's custom delimiter and the delimiter, thus obtaining the corresponding object result. The following example:
Example 1:querystring.parse ("string", "delimiter", "quantifier")
- var querystring = require(' querystring ');
- var result = querystring. Parse(' [email protected][email protected][email protected] ',' @ ',' $ ');
- Console. Log(result);
Operation Result:
- { foo: ', bar: ' cool ', xux: ' cool ', yys : ' }
node. js (v) string conversion