【问题标题】:How to show full JSON response in console from Axios GET request如何在控制台中显示来自 Axios GET 请求的完整 JSON 响应
【发布时间】:2022-01-07 04:14:01
【问题描述】:

我的问题是我需要查看所有项目。当我运行我的脚本时,我在我的日志中得到了一个对象数组,但它并没有全部显示出来 ... 40541 更多项目 不是预期的,我正在尝试记录所有项目

[
    {},
    {},
    ... 40541 more items
]

在我的控制台中运行 npm run start 后,我的 package.json 将所有数据记录到 reportData.log。这是我的 package.json 的脚本部分

"scripts": {
    "start": "node --experimental-json-modules reportScript.js > reportData.log"
  },

这是我reportScript.js中的代码,已添加伪变量

function getReport() {
    axios({
        method: 'get',
        url: reportEndpoint, //not actual, just pseudo
        headers: {
            'Content-Type':'application/json', 
            'Cookie':`sess.jwt=${sessJwt}`, //not actual, just pseudo
            'integration-key': `${integrationKey}`//not actual, just pseudo
        }
    })
    .then(response => {
        var reportResponse = response.data;
        console.log(reportResponse);
    })
}

【问题讨论】:

标签: javascript node.js unix axios console


【解决方案1】:

我认为你应该像这样在 axios args 对象中添加{responseType: 'json'}

axios({
        method: 'get',
        url: reportEndpoint, 
        responseType: 'json',
        headers: {
            'Content-Type':'application/json', 
            'Cookie':`sess.jwt=${sessJwt}`, 
            'integration-key': `${integrationKey}`
        }
    })

如果您仍然无法在控制台中获取对象内容 bcoz,我们无法看到所有数据,如果您使用的是小数据,那么您有时会看到它。

否则你可以在浏览器上渲染你的数据,最好在浏览器中使用 json 扩展。

【讨论】:

    猜你喜欢
    • 2021-06-27
    • 1970-01-01
    • 2022-01-13
    • 2020-05-21
    • 2021-06-20
    • 1970-01-01
    • 2021-08-01
    • 2019-06-08
    • 1970-01-01
    相关资源
    最近更新 更多