const qs =require(‘querystring‘);
var str="uname=tom&upwd=123&pno=33&kw=js;"
//查询字符串转成对象
var obj=qs.parse(str);
console.log(obj) // 输出JS对象{uname:‘tom‘....}
console.log(obj.uname); //输出字符串
//对象转成查询字符串
var obj2 = {ename:"强东",age:20,addr:"bj"};
var str = qs.stringify(obj2);
console.log(str);
时间: 2024-10-29 10:46:50