首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用res.send()使用express with节点发送数字

无法使用res.send()使用express with节点发送数字
EN

Stack Overflow用户
提问于 2016-09-14 19:52:24
回答 3查看 9.3K关注 0票数 13

我正在努力获得"imdb评分“使用速递节点,我正在努力。

movies.json

代码语言:javascript
复制
[{
"id": "3962210",
"order": [4.361276149749756, 1988],
"fields": {
    "year": 2015,
    "title": "David and Goliath",
    "director": "Timothy A. Chey"
},
"doc": {
    "_id": "3962210",
    "_rev": "1-ac648e016b0def40382d5d1b9ec33661",
    "title": "David and Goliath",
    "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",
    "title": "David Cross: The Pride Is Back",
    "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

我哪里出问题了?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-09-14 19:56:27

根据Express res.send([body])文档:

主体参数可以是缓冲区对象、字符串、对象或数组

你不能单独发送一个号码。

尝试将数字转换为字符串

代码语言:javascript
复制
res.send(''+result.rows[0].doc.imdb.rating);

或将其作为对象值发送。

代码语言:javascript
复制
res.send({ result: result.rows[0].doc.imdb.rating});
票数 19
EN

Stack Overflow用户

发布于 2020-03-15 05:33:36

这是可行的,您必须将其转换为字符串: threeFunction().toString()或x1.toString()

票数 0
EN

Stack Overflow用户

发布于 2020-09-29 00:23:38

整数对res.send()无效,因此将其转换为字符串。

代码语言:javascript
复制
res.send(value.toString())
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39498601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档