[英]Send json to jade
I am sending a big json file from server to jade, but the "
are replaced with: "
therefor the json is unreadable/unparsable and I get this error: 我正在从服务器向玉器发送一个大的json文件,但是
"
被替换为: "
因此json无法读取/无法解析,并且出现此错误:
Uncaught SyntaxError: Unexpected token &
I send the data like this from node: 我从节点发送这样的数据:
res.render(view, {world:{name:"SomeName",width:50},otherdata:{...}});
and then get it in jade like this: 然后像这样在翡翠中得到它:
doStuff(JSON.parse(#{data}));
and here it is unreadable data which looks like: 这里是不可读取的数据,看起来像:
{world:{name:"SomeName",width:50...
can I somehow disable the conversion of the quotes? 如何以某种方式禁用引号的转换?
No experience with jade but from the language reference ( http://jade-lang.com/reference/interpolation/ ) i guess 我没有玉的经验,但从语言参考( http://jade-lang.com/reference/interpolation/ )
doStuff(JSON.parse(!{data}))
might work 可能有用
Server side within your rout you will do the following consider the object user
在您的溃败中,服务器端您将考虑以下对象
user
var user = {username:"myname"};
res.locals.user = user ;
response will be : 响应将是:
res.render('view');
jade view will have the variable available : 翡翠视图将具有可用变量:
if user
script(type='text/javascript').
var user = !{JSON.stringify(user)};
Try adding app.use(bodyParser.json());
尝试添加
app.use(bodyParser.json());
if you still have the issue 如果你还有问题
hope that helps 希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.