parsingNodejs响应之后。 JSON响应结果数组仅作为对象输出。 我如何开始显示对象

在这里我称之为模块。 然后请求回应。 那么我使用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); }); 

我相信一个控制台日志不会输出嵌套的对象,所以你的回应可能是好的,你只是不能在控制台中看到它。

如果你想检查它,你可以使用一个debugging器并检查你的variables,或者使用util.inspect()

看到这个答案

编辑:在Chrome中的控制台将显示嵌套的对象,但节点的控制台不会默认扩展对象 – 感谢杰里米Thille的评论