わかりました、こんにちは、私は非同期で約束を返すものを持っています。基本的には、.then メソッドまたはそれが呼び出されたものを使用しました。ログに記録したい変数 + カスタム文字列 (console.log(data+"hey");) を console.log() すると、データのみの変数を実行するとログ [オブジェクト、オブジェクト] が得られますが、それは私に与えますまさに私が欲しいもの。なぜこれが起こっているのですか?これが私のコードです。
(このコードは、Steam のインベントリにあるアイテムを取得します。):
var steamUserInventory = require('steam-user-inventory');
var botID64 = "76561198026027024";
steamUserInventory(botID64, '753/6').then(data => console.log(data));
これは完璧に機能します(console.logのデータは単独であるため)また、次のようにjsonファイルに「データ」を入れようとすると:
steamUserInventory(Bot, '753/6').then(data =>
fs.writeFile("inventories/me.json", data, function(err) {
if(err) {
console.log("Error saving data to json file: " + err);
return;
}
console.log("Bot inventory has been updated!");
}));
それは私に同じ古き良き[オブジェクト、オブジェクト]..より多くの行を与えます
json ファイルで。それは私が欲しいものを私に与えません。
(ところで、console.log(data)は私に与えます):
{ id: '538277908',
amount: '1',
pos: 126,
name: 'Docking',
appid: '753', classid: '230924010',
instanceid: '2108281766', tradable: 0,
marketable: 0, marketTradableRestriction: '7',
link: 'http://cdn.akamai.steamstatic.com/steamcommunity/public/images/items/2870/5059522765a958a85cabe31988ccc928b8c36715.jpg',
image: 'http://steamcommunity-a.akamaihd.net/economy/image/U8721VM9p9C2v1o6cKJ4qEnGqnE7IoTQgZI-VTdwyTBeimAcIoxXpgK8bPeslY9pPJIvB5IWW2-452kaM8heLSRgleGBrrJJ3upnaKks0uKrDFhw5OJPBT3mTBHXgjSUcef3xwM2PZYmJ0fxw5kZ79tJA8F0arJkgNs',
category: null, type: null,
exterior: null, quality:
これは、jsonファイルに保存したいものです。
御時間ありがとうございます。