📜  将 cookie 转换为 json javascript 代码示例

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

代码示例1
let cookie = "referer=example.com/post?id=22;bcomID=8075; subreturn=example&fuzzy=true&ct=null&autobounce=true; JSESSIONID=6D20570E1EB; mbox=session"; // sample cookies
let output = {};
cookie.split(/\s*;\s*/).forEach(function(pair) {
  pair = pair.split(/\s*=\s*/);
  output[pair[0]] = pair.splice(1).join('=');
});
let json = JSON.stringify(output, null, 4);
console.log(json);