我收到來自HTTP post作爲json對象數組的響應。但想顯示爲字符串。請參閱我的回覆..如何將json對象的數組轉換爲Nodejs中的String?
{ total: 14,
results:
[ { name: [Object],
comments: [],
attributes: [Object],
type: [Object],
context: [Object],
status: 'Accepted',
score: 1.7646775,
modified: 1426085315767,
parents: [] },
{ name: [Object],
comments: [],
attributes: [Object],
type: [Object],
context: [Object],
status: 'Accepted',
score: 1.3945999,
modified: 1425386916807,
parents: [] },
下面的代碼顯示響應。
function(error, response, data){
if(error) {
console.log(error);
} else {
console.log(data);
}
可你只需要使用'的console.log(JSON.stringify(數據))'? –
你可以這樣做:'const arrAsStr = arr.map((r)=> JSON.stringify(r));' – Hosar