Reputation: 2053
I'm setting a cookie that stores some of my JSON data. Something along the lines of:
$.cookie('user-info', JSON.stringify(locationInfo));
So the cookie value looks something like:
{"city":"New York","state":"NY","zip":"90210"}
How would I go about simply changing the "zip" value so instead of 90210 I want it to be 10101. I tried something along the lines of:
$.cookie('user-info', { zip: '10101' });
But this doesn't seem to be updating anything. Any ideas? Thanks in advance.
Upvotes: 0
Views: 1290
Reputation: 104775
Something like:
var cookieObj = $.parseJSON($.cookie('user-info')); //might be done automatically, not sure
cookieObj.zip = 10101;
$.cookie('user-info', JSON.stringify(cookieObj));
Upvotes: 3