📌  相关文章
📜  来自对象 js 的查询字符串 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:52.588000             🧑  作者: Mango

代码示例3
function objectToQueryString(obj) {
  var str = [];
  for (var p in obj)
    if (obj.hasOwnProperty(p)) {
      str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
    }
  return str.join("&");
}

var person = { first_name : "Marty",last_name : "Mcfly"};
var queryString=objectToQueryString(person); //"first_name=Marty&last_name=Mcfly"