Query-string encoding of a Javascript Object

前端 未结 30 2914
渐次进展
渐次进展 2020-11-22 00:23

Do you know a fast and simple way to encode a Javascript Object into a string that I can pass via a GET Request?

No jQuery, no

30条回答
  •  旧巷少年郎
    2020-11-22 00:56

    With Node.js v6.6.3

    const querystring = require('querystring')
    
    const obj = {
      foo: 'bar',
      baz: 'tor'
    }
    
    let result = querystring.stringify(obj)
    // foo=bar&baz=tor
    

    Reference: https://nodejs.org/api/querystring.html

提交回复
热议问题