Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejs教程14:querystring模块 #45

Open
chencl1986 opened this issue Mar 18, 2019 · 0 comments
Open

Nodejs教程14:querystring模块 #45

chencl1986 opened this issue Mar 18, 2019 · 0 comments

Comments

@chencl1986
Copy link
Owner

阅读更多系列文章请访问我的GitHub博客,示例代码请访问这里

querystring

querystring用来对url中的query字符串进行解析,常用的方法有querystring.parse和querystring.stringify。

querystring.parse

querystring.parse方法用于解析URL 查询字符串。

示例代码:/lesson14/querystring.js

代码如下:

const querystring = require('querystring')

console.log(querystring.parse('foo=bar&abc=xyz&abc=123'))

解析结果为:

{ foo: 'bar', abc: [ 'xyz', '123' ] }

querystring.stringify

querystring.stringify用于将对象转换为URL查询字符串。

示例代码:/lesson14/querystring.js

代码如下:

console.log(querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' }))

解析结果为:

foo=bar&baz=qux&baz=quux&corge=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant