【发布时间】:2018-11-10 02:49:36
【问题描述】:
我有以下格式存储的 cookie 值
{stamp:'HMzWoJn8V4ZkdRN1DduMHLhS3dKiDDr6VoXCjjeuDMO2w6V+n2CcOg==',necessary:true,preferences:true,statistics:true,marketing:false,ver:1}
我需要阅读以下值
necessary
preferences
statistics
marketing
不确定如何正确读取值,假设它是 JSON 格式,我尝试了以下代码
Cookies.get('CookieConsent')
//Parse the cookie to Object
cookieval = Cookies.get('CookieConsent');
console.log(cookieval);
console.log("Necessary: " + Boolean(cookieval.necessary));
console.log("Prefrences: " + Boolean(cookieval.preferences));
console.log("Statistics: " + Boolean(cookieval.statistics));
console.log("Marketing: " + Boolean(cookieval.marketing));
但是这段代码总是返回 false。
我使用以下 Jquery 读取 Cookie 值https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js
【问题讨论】:
标签: javascript jquery jquery-cookie