我在 Node.js 中运行了以下代码
const request = require("request");
const GetUserInventory = {
method: 'GET',
url: 'https://api-trade.opskins.com/ITrade/GetUserInventory/v1/',
qs: { uid: '3192035', app_id: '1' },
json: true
};
request(GetUserInventory, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
我得到的输出如下。这里不显示字符串的值。也就是说,它们显示为 [object] 如何获得如图所示的所需输出?
{
status: 1,
time: 1536729167,
current_page: 1,
total_pages: 1,
response: {
items: [
[Object]
],
total: '1',
items_in_active_offers: null,
user_data: {
username: 'Mowrish gamdom.com',
avatar: 'https://steamcdn-a.opskins.media/steamcommunity/public/images/avatars/d7/d7cf2c088d4398bed904ae540b36211e1af202f2.jpg'
},
sort_parameters: [
[Object],
[Object],
[Object],
[Object],
[Object],
[Object]
]
}
}
我期望的输出如下。如何获得这个输出?
我在 console.log() 之前尝试过 body
的 JSON.parse
而不是 GetUserInventory 中的 json: true
值。它不起作用。另外,我尝试了 body
的 JSON.stringify
。同样的情况也发生了
最佳答案
如果您希望输出与您发布的屏幕截图相同,请尝试以下操作
request(GetUserInventory, function (error, response, body) {
if (error) throw new Error(error);
obj = JSON.stringify(body);
console.log(obj);
});
关于JSON - 多行字符串输出的数组错误 Node js | Node 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52288124/