如何解决无法使用带有节点的express的res.send发送号码
body参数可以是Buffer对象,String,对象或Array。
您不能自己发送号码。
尝试将数字转换为字符串
res.send(''+result.rows[0].doc.imdb.rating);
或将其作为对象值发送
res.send({ result: result.rows[0].doc.imdb.rating});
解决方法
我试图在节点中使用express来获得“ imdb评级”,我正在努力。
电影.json
[{
"id": "3962210","order": [4.361276149749756,1988],"fields": {
"year": 2015,"title": "David and Goliath","director": "Timothy A. Chey"
},"doc": {
"_id": "3962210","_rev": "1-ac648e016b0def40382d5d1b9ec33661","year": 2015,"rating": "PG","runtime": "92 min","genre": ["Drama"],"director": "Timothy A. Chey","writer": ["Timothy A. Chey"],"cast": ["Miles Sloman","Jerry Sokolosky","Makenna Guyler","Paul Hughes"],"poster": "http://ia.media-imdb.com/images/M/MV5BMjA3OTQ4NDc4MV5BMl5BanBnXkFtZTgwNDYwMzA1MjE@._V1_SX300.jpg","imdb": {
"rating": 8.4,"votes": 138,"id": "tt3962210"
}
}
},{
"id": "251656","order": [3.489020824432373,686],"fields": {
"year": 1999,"title": "David Cross: The Pride Is Back","director": "Troy Miller"
},"doc": {
"_id": "251656","_rev": "1-2d0762776874f94af8f2d76e5991b529","year": 1999,"rating": null,"runtime": "55 min","genre": ["Comedy"],"director": "Troy Miller","writer": ["David Cross"],"cast": ["David Cross","Molly Brenner","Amiira Ruotola"],"poster": "http://ia.media-imdb.com/images/M/MV5BODcwMjMxOTU4OF5BMl5BanBnXkFtZTgwODE0MTc4MTE@._V1_SX300.jpg","imdb": {
"rating": 7.9,"votes": 380,"id": "tt0251656"
}
}
}]
结果
res.send(result.rows[0].doc.imdb);
退货
{"rating":8.4,"votes":138,"id":"tt3962210"}
但
res.send(result.rows[0].doc.imdb.rating);
//不返回8.4,只是崩溃的节点
和
res.send(result.rows[0].doc.title);
//返回David和Goliath
res.send(result.rows[0].doc.cast[0]);
//返回Miles Sloman
我要去哪里错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。