是的,Node.js 可以使用内置的 http 模块或第三方模块如 axiosrequest 发送 HTTP 请求并获取 JSON 数据。以下是一个使用 axios 模块获取 JSON 数据的示例:

const axios = require('axios');

axios.get('https://example.com/api/data')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

此代码将发送 GET 请求到 https://example.com/api/data,并将响应数据打印到控制台。请注意,response.data 是一个包含 JSON 数据的 JavaScript 对象。

nodejs 可以request json吗

原文地址: http://www.cveoy.top/t/topic/fjL1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录