在express.js中设置cookie出现j:前缀 [英] Set cookie in express.js appear j: prefix
本文介绍了在express.js中设置cookie出现j:前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用res.cookie设置cookie,如下所示:
I'm trying to set cookie using res.cookie like below:
res.cookie('userId',req.user._id); //set cookie here
console.log(req.user._id); //returned correct value, eg abc
然后我在我的cookie中看到j:abc ,为什么会发生这种情况?
then I'm seeing j:"abc" in my cookie, why does this happens?
推荐答案
我知道这有点晚了,但我自己也遇到过这个问题而且一直在挖掘一点点。看起来他们用j:为任何JSON字符串添加前缀,因此他们知道在解析它时它是一个JSON字符串。这基本上意味着你必须手动删除j:,如果你正在使用其他方式解析它。
I know this is a bit late, but I came across this issue myself and have been digging around a bit. It seems they're prefixing any JSON strings with "j:" so they know it's a JSON string when parsing it back. What this basically means is that you have to manually remove the "j:" if you're using some other way of parsing it.
这篇关于在express.js中设置cookie出现j:前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文