📌  相关文章
📜  对象查询字符串 javascript 代码示例

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

代码示例6
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"