javascript - Why when i set cookies in PHP with json array, does is show % sign?

Solution:

Cookies are automatically URL encoded when sent, to set a raw cookie you should use the setrawcookie function

$cookieData=array(
   's1q1' => 'test',
   's1q2' => 'test2',
);
setrawcookie('calcCookie', json_encode($cookieData), time()+24*60*60*1000);

Note: Not sure they would be appropriately decoded back when you access them.

Answer

Solution:

bit clunky but this solved the issue:

in js:
var cookie = getCookie('calcCookie');

cookie = cookie.replace(/%7B/g, "{").replace(/%22/g, '"').replace(/%7D/g, "}").replace(/%3A/g, ":").replace(/%2C/g, ",")

cookie = JSON.parse(cookie)

Source