Query String——NodeJS 6.9.1 官方文档
parse
querystring.parse(str[, sep[, eq[, options]]])
- str <String> The URL query string to parse
- sep <String> The substring used to delimit key and value pairs in the query string. Defaults to '&'.
- eq <String>. The substring used to delimit keys and values in the query string. Defaults to '='.
- options <Object>
decodeURIComponent <Function> The function to use when decoding percent-encoded characters in the query string. Defaults to querystring.unescape().
maxKeys <number> Specifies the maximum number of keys to parse. Defaults to 1000. Specify 0 to remove key counting limitations.
【实例】
> querystring.parse('name=zdy&ability=js&ability=python&from=')
{ name: 'zdy', ability: [ 'js', 'python' ], from: '' }
> querystring.parse('name=zdy,ability=js,ability=python,from=',',')
{ name: 'zdy', ability: [ 'js', 'python' ], from: '' }
> querystring.parse('name:zdy,ability:js,ability:python,from:',',',':')
{ name: 'zdy', ability: [ 'js', 'python' ], from: '' }
> querystring.parse('name:zdy,ability:js,ability:python,from:',',')
{ 'name:zdy': '',
'ability:js': '',
'ability:python': '',
'from:': '' }
> querystring.parse('name:zdy,ability:js,ability:python,from:')
{ 'name:zdy,ability:js,ability:python,from:': '' }
stringify
querystring.stringify(obj[, sep[, eq[, options]]])
- obj <Object> The object to serialize into a URL query string
- sep <String> The substring used to delimit key and value pairs in the query string. Defaults to '&'.
- eq <String>. The substring used to delimit keys and values in the query string. Defaults to '='.
- options
encodeURIComponent <Function> The function to use when converting URL-unsafe characters to percent-encoding in the query string. Defaults to querystring.escape().
【实例】
> querystring.stringify({name:'zdy',ability:['js','python'],from:''})
'name=zdy&ability=js&ability=python&from='
> querystring.stringify({name:'zdy',ability:['js','python'],from:''},',')
'name=zdy,ability=js,ability=python,from='
> querystring.stringify({name:'zdy',ability:['js','python'],from:''},',',':')
'name:zdy,ability:js,ability:python,from:'
secape
querystring.escape(str)
The querystring.escape() method performs URL percent-encoding on the given str in a manner that is optimized for the specific requirements of URL query strings.
【实例】
> querystring.escape('<张丹阳>')
'%3C%E5%BC%A0%E4%B8%B9%E9%98%B3%3E'
unescape
querystring.unescape(str)
The querystring.unescape() method performs decoding of URL percent-encoded characters on the given str.
【实例】
> querystring.unescape('<张丹阳>')
'<张丹阳>'