NodeJS——Query String

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('<张丹阳>')
'<张丹阳>'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,212评论 19 139
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,550评论 0 23
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,969评论 0 0
  • 说好每天都写一点文字,但是还是没有坚持下来。一直都觉得写东西非得要灵感来了才可以,强求不得,所以觉得以文字为生的人...
    袋鼠的尾巴阅读 1,679评论 1 2
  • 要想在事业上获得真正的成功,你就必须拥有精神生活带给你的深刻见解,鱼和熊掌是可以兼得的,感恩《能断金刚》让我具...
    雪域红梅阅读 1,328评论 0 0

友情链接更多精彩内容