gpt4 book ai didi

javascript - 解析 Nodejs 响应后。 JSON 响应结果数组仅作为对象输出。我如何才能显示对象

转载 作者:可可西里 更新时间:2023-11-01 17:25:53 24 4
gpt4 key购买 nike

这里我调用模块。然后要求回复。然后我使用 JSON.parse 响应的主体,但输出如下所示。

{ response:
{ status: 'ok',
userTier: 'developer',
total: 240,
startIndex: 1,
pageSize: 1,
currentPage: 1,
pages: 240,
orderBy: 'newest',
results: [ [Object] ] } }

我希望能够看到对象

    {
"response": {
"status": "ok",
"userTier": "developer",
"total": 240,
"startIndex": 1,
"pageSize": 1,
"currentPage": 1,
"pages": 240,
"orderBy": "newest",
"results": [{
"id": "sustainable-business/2017/jun/13/battery-storage-and-rooftop-solar-could-mean-new-life-post-grid-for-consumers",
"type": "article",
"sectionId": "sustainable-business",
"sectionName": "Guardian Sustainable Business",
"webPublicationDate": "2017-06-12T23:51:00Z",
"webTitle": "Battery storage and rooftop solar could mean new life post-grid for consumers",
"webUrl": "https://www.theguardian.com/sustainable-business/2017/jun/13/battery-storage-and-rooftop-solar-could-mean-new-life-post-grid-for-consumers",
"apiUrl": "https://content.guardianapis.com/sustainable-business/2017/jun/13/battery-storage-and-rooftop-solar-could-mean-new-life-post-grid-for-consumers",
"isHosted": false
}]
}
}

这是代码

function prettyJSON(data) {
return JSON.stringify(data,null," ");
}


api.custom.search({fromDate:"2017-06-12",
toDate:"2017-06-12",
orderBy:"newest",
//showFields:"all",
pageSize: 2})
.then(function(response){
var reqBody = response.body.toString();
reqBody = JSON.parse(reqBody);
console.log(reqBody);

})

.catch(function(err){
console.log(err);
});

最佳答案

我相信控制台日志不会输出嵌套对象,因此您的响应可能没问题,只是您无法在控制台中看到它。

如果你想检查它,你可以使用调试器并在那里检查你的变量,或者使用 util.inspect()

参见 this回答

编辑:Chrome 中的控制台将显示嵌套对象,但默认情况下 Node 的控制台不会扩展对象 - 感谢 Jeremy Thille 的评论

关于javascript - 解析 Nodejs 响应后。 JSON 响应结果数组仅作为对象输出。我如何才能显示对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47715660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com