Express documentation says that we can set a cookie with an object using this function:
res.cookie('cart', { items: [1,2,3] });
I want to retrieve this value using Angular ngCookie:
var cart= $cookies.getObject('cart');
But it throw an error:
SyntaxError: Unexpected token j
I can retrieve the string value of the cookie using $cookie.get('cart')
, and, indeed, it looks like this:
j:{ "items": [1,2,3] }
I know I can remove the characters and then parse the object, but I'd rather have a more generic method.
Can I force Express to not set the cookie with this syntax (without "j:")?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…