You do not have JSON format - you have something closer to JS object literal notation, except that it's a string rather than JS code, so can't use JSON.parse
unfortunately.
If the values don't have commas or colons, you can split
the string by commas and reduce
into an object:
const input = `{stamp:'HMzWoJn8V4ZkdRN1DduMHLhS3dKiDDr6VoXCjjeuDMO2w6V+n2CcOg==',necessary:true,preferences:true,statistics:true,marketing:false,ver:1}`;
const obj = input
.slice(1, input.length - 1)
.split(',')
.reduce((obj, str) => {
const [key, val] = str.split(':');
obj[key] = val;
return obj;
}, {});
console.log(obj);
Wrap this string by (
and )
. Then parse like as display follow
Attention! But you need be ensure input
string (which received from cookie) not contains bad code. Such as unknown injected function. In this case, the function will be executed on client browser, with access to private data (cookie, localStorage, data from html-forms).
const input = "{stamp:'HMzWoJn8V4ZkdRN1DduMHLhS3dKiDDr6VoXCjjeuDMO2w6V+n2CcOg==',necessary:true,preferences:true,statistics:true,marketing:false,ver:1}"
const object = eval("(" + input + ")");
alert(object.necessary);
Here's my plunker. If you click on the profile link and look at the generated state change list: stateChanges = [ " -> home", "home -> profile", "home -> signIn", "signIn -> ...
Here's my plunker. If you click on the profile link and look at the generated state change list: stateChanges = [ " -> home", "home -> profile", "home -> signIn", "signIn -> ...
Trying to understand the behaviour and difference between: moment.utc(date) and moment(date).utc() Using '2018-05-31' as a param: moment.utc('2018-05-31').format() will give: 2018-05-31T00:00:...
Trying to understand the behaviour and difference between: moment.utc(date) and moment(date).utc() Using '2018-05-31' as a param: moment.utc('2018-05-31').format() will give: 2018-05-31T00:00:...
I am working on a React app that is 'remote controlled' and am trying to connect the app's tab navigation via Pusher. I am using react-router-dom and have set up my connection to Pusher and the ...
I am working on a React app that is 'remote controlled' and am trying to connect the app's tab navigation via Pusher. I am using react-router-dom and have set up my connection to Pusher and the ...
I have a temperature scale (green up to some extent, then yellow and then red) in the background and need a temperature "bar" of sorts over it which: Refreshes after a fixed interval of time, in the ...
I have a temperature scale (green up to some extent, then yellow and then red) in the background and need a temperature "bar" of sorts over it which: Refreshes after a fixed interval of time, in the ...