【发布时间】:2017-12-14 11:23:18
【问题描述】:
我想发出一个 URL 请求,在我在浏览器中尝试后,它的结果将是 JSON。
我想将整个 JSON 响应放在 var 或 const 中,以便以后进行进一步处理。
到目前为止我所尝试的:
app.use(express.bodyParser());
app.post(MY_URL, function(request, response){
console.log(request.body);
console.log(request.body;
});
然后:
app.use(bodyParser.urlencoded({
extended: true
}));
app.post(MY_URL, function (req, res) {
console.log(req.body)
});
这两个都没有解决,成为node.js 的初学者也无济于事。
编辑:为了澄清我的问题:
my_url = https://only_an_example
在浏览器中输入的 URL 将在该页面中提供一个 Json,如下所示:
{
"query": "testing",
"topScoringIntent": {
"intent": "Calendar.Add",
"score": 0.987683
},
"intents": [
{
"intent": "Calendar.Add",
"score": 0.987683
},
{
"intent": "None",
"score": 0.0250480156
}}
我想要的是获得 Json 响应并使用 node.js 打印它。
【问题讨论】:
-
看来您需要访问 "response.body" 或 "res.body" 。不要求
-
如果您发现问题所在或有更好的建议方式,您能否在答案中添加完整的回复。
-
如果你想获取 Json 然后使用
app.get,app.post只是用于向服务器发送数据,但我也可以返回 json 数据 -
我想发送 URL 然后检索输出,所以我想我需要同时使用这两个?
标签: javascript json node.js