小编boo*_*boo的帖子

9
推荐指数
2
解决办法
1万
查看次数

TypeError:res.json不是函数

我正在尝试发送两个json但它不起作用.它打印TypeError: res.json is not a function但我不明白为什么会发生.有什么想法吗?谢谢 !!

app.post('/danger', function response(req, res) {
    let placeId = req.body.data;
    let option = {
      uri: 'https://maps.googleapis.com/maps/api/directions/json?',
      qs: {
        origin:`place_id:${placeId[0]}`, destination: `place_id:${placeId[1]}`,
        language: 'en', mode: 'walking', alternatives: true, key: APIKey
      }
    };
    rp(option)
      .then(function(res) {
        let dangerRate = dangerTest(JSON.parse(res), riskGrid);
        res.json({ data: [res, dangerRate]});
      })
      .catch(function(err) {
        console.error("Failed to get JSON from Google API", err);
      })
});
Run Code Online (Sandbox Code Playgroud)

javascript json node.js express

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

javascript ×2

express ×1

json ×1

node.js ×1

vue-component ×1

vue.js ×1

vuejs2 ×1