Query String——NodeJS 6.9.1 官方文档
parse
querystring.parse(str[, sep[, eq[, options]]])
- str
The URL query string to parse - sep
The substring used to delimit key and value pairs in the query string. Defaults to '&'. - eq
. The substring used to delimit keys and values in the query string. Defaults to '='. - options
decodeURIComponent
maxKeys
【实例】
> 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
- sep
The substring used to delimit key and value pairs in the query string. Defaults to '&'. - eq
. The substring used to delimit keys and values in the query string. Defaults to '='. - options
encodeURIComponent
【实例】
> 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('<张丹阳>')
'<张丹阳>'