[英]Parsing JSON in Jade?
I have ben scratching my head.我一直在挠头。 I am trying to parse JSON in Jade.我正在尝试在 Jade 中解析 JSON。 I have tried about 20 solutions I found on Stack... does anyone see what I am doing wrong here?我已经尝试了我在 Stack 上找到的大约 20 个解决方案......有没有人看到我在这里做错了什么?
route (data from postgres):路线(来自postgres的数据):
//show books
pg.connect(dbconnect, function(err, client, done) {
client.query('SELECT * FROM books', function(err, result) {
res.render('books', { title: 'My Books', booklist: JSON.stringify(result.rows) });
});
});
Jade:玉:
block content
each key in booklist
p= bookname
Output:输出:
[{"id":1,"bookname":"Book 1"},{"id":2,"bookname":"Book 2"}]
Any help appreciated!任何帮助表示赞赏!
The problem is likely that you cast your object to a string with JSON.stringify()
.问题很可能是您使用JSON.stringify()
将对象转换为字符串。 That function will return a string, which you then are trying to iterate over.该函数将返回一个字符串,然后您尝试对其进行迭代。
Try尝试
pg.connect(dbconnect, function(err, client, done) {
client.query('SELECT * FROM books', function(err, result) {
res.render('books', { title: 'My Books', booklist: result.rows });
});
});
and和
block content
each book in booklist
p= book.bookname
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.