Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
某些JSON对象未定义_Json_Node.js - Fatal编程技术网

某些JSON对象未定义

某些JSON对象未定义,json,node.js,Json,Node.js,所以我正在使用nodeJS和Steam-API来尝试制作一个交易机器人 我需要知道收到了哪些物品,但我什么时候收到 undefined 以下是JSON: { "partner":{ "universe":1, "type":1, "instance":1, "accountid":369917733 }, "id":"2112720622", "message":"No need to accept, ju

所以我正在使用nodeJS和Steam-API来尝试制作一个交易机器人 我需要知道收到了哪些物品,但我什么时候收到

undefined
以下是JSON:

    {  
   "partner":{  
      "universe":1,
      "type":1,
      "instance":1,
      "accountid":369917733
   },
   "id":"2112720622",
   "message":"No need to accept, just testing out a bot.",
   "state":3,
   "itemsToGive":[  

   ],
   "itemsToReceive":[  
      {  
         "appid":730,
         "contextid":"2",
         "assetid":"10168993563",
         "classid":"1989300153",
         "instanceid":"302028390",
         "amount":1,
         "missing":true,
         "icon_url":"IzMF03bi9WpSBq-S-ekoE33L-iLqGFHVaU25ZzQNQcXdB2ozio1RrlIWFK3UfvMYB8UsvjiMXojflsZalyxSh31CIyHz2GZ-KuFpPsrTzBG0qe6yD3n-ZDLdYXKOTVxqTudcPGjZrGLx5ujCF2nASeh-EF9XdfEAo2JLNZiKahtv0oMVu2u_0UdyEhk6f9BKZAarxm1OMLh9m3IWGBD1M58",
         "icon_url_large":"IzMF03bi9WpSBq-S-ekoE33L-iLqGFHVaU25ZzQNQcXdB2ozio1RrlIWFK3UfvMYB8UsvjiMXojflsZalyxSh31CIyHz2GZ-KuFpPsrTzBG0qe6yD3n-ZDLdEC3YDlltU-cLND7c92Hxt-SVFGqfFe54SgACdfcFoDJPP82AOBtrhdZZ-Ga9zhwzDhgvNMZJfACpx2EfJbQ1xDhPJM5amiekAf1NktA",
         "icon_drag_url":"",
         "name":"Sealed Graffiti | Still Happy (Desert Amber)",
         "market_hash_name":"Sealed Graffiti | Still Happy (Desert Amber)",
         "market_name":"Sealed Graffiti | Still Happy (Desert Amber)",
         "name_color":"D2D2D2",
         "background_color":"",
         "type":"Base Grade Graffiti",
         "tradable":true,
         "marketable":true,
         "commodity":true,
         "market_tradable_restriction":7,
         "fraudwarnings":[  

         ],
         "descriptions":[  
            {  
               "type":"html",
               "value":"This is a sealed container of a graffiti pattern. Once this graffiti pattern is unsealed, it will provide you with enough charges to apply the graffiti pattern <b>50</b> times to the in-game world.",
               "app_data":""
            },
            {  
               "type":"html",
               "value":" ",
               "app_data":""
            },
            {  
               "type":"html",
               "value":"",
               "color":"00a000",
               "app_data":{  
                  "limited":"1"
               }
            }
         ],
         "owner_descriptions":[  

         ],
         "actions":[  
            {  
               "name":"Inspect in Game...",
               "link":"steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S%owner_steamid%A%assetid%D9253357711394385702"
            }
         ],
         "market_actions":{  
            "0":{  
               "name":"Inspect in Game...",
               "link":"steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D9253357711394385702"
            }
         },
         "tags":[  
            {  
               "internal_name":"CSGO_Type_Spray",
               "name":"Graffiti",
               "category":"Type",
               "category_name":"Type"
            },
            {  
               "internal_name":"normal",
               "name":"Normal",
               "category":"Quality",
               "category_name":"Category"
            },
            {  
               "internal_name":"Rarity_Common",
               "name":"Base Grade",
               "category":"Rarity",
               "color":"b0c3d9",
               "category_name":"Quality"
            },
            {  
               "internal_name":"Tint5",
               "name":"Desert Amber",
               "category":"SprayColorCategory",
               "category_name":"Graffiti Color"
            }
         ],
         "id":"10168993563",
         "owner_actions":[  

         ],
         "market_marketable_restriction":0
      }
   ],
   "isOurOffer":true,
   "created":"2017-05-13T09:50:24.000Z",
   "updated":"2017-05-13T09:50:48.000Z",
   "expires":"2017-05-27T09:50:24.000Z",
   "tradeID":"1915564581201455085",
   "fromRealTimeTrade":false,
   "confirmationMethod":0,
   "escrowEnds":null,
   "rawJson":"{\n\t\"tradeofferid\": \"2112720622\",\n\t\"accountid_other\": 369917733,\n\t\"message\": \"No need to accept, just testing out a bot.\",\n\t\"expiration_time\": 1495878624,\n\t\"trade_offer_state\": 3,\n\t\"items_to_receive\": [\n\t\t{\n\t\t\t\"appid\": \"730\",\n\t\t\t\"contextid\": \"2\",\n\t\t\t\"assetid\": \"10168993563\",\n\t\t\t\"classid\": \"1989300153\",\n\t\t\t\"instanceid\": \"302028390\",\n\t\t\t\"amount\": \"1\",\n\t\t\t\"missing\": true\n\t\t}\n\t],\n\t\"is_our_offer\": true,\n\t\"time_created\": 1494669024,\n\t\"time_updated\": 1494669048,\n\t\"tradeid\": \"1915564581201455085\",\n\t\"from_real_time_trade\": false,\n\t\"escrow_end_date\": 0,\n\t\"confirmation_method\": 0\n}"
}

为什么它只对其中一个对象执行此操作?

也许您可以使用for来记录itemToReceive的每个项目

大概是这样的:

manager.on('sentOfferChanged', function(offer, oldState) {
    var state = offer.state;
    if(state == 3) {
        console.log("Offer " + offer.id + " was accepted");
        console.log("[Offer #" + offer.id + "] The following items was recieved: ");

       for(var i in itemstoReceive)
         {
           var name = itemsToReceive[i].name;
           console.log(name);
             }}
});

没有足够的信息。由于JSON是有效的,并且您说您正在使用流,我唯一想到的是流还没有完成。您尚未收到整个流。请显示您的请求。我猜是异步问题。@JuanGG我从没说过我用过streams@FazalRasel更新谢谢你的更新。请发布您用于“获取
itemsToRecieve
”的代码
manager.on('sentOfferChanged', function(offer, oldState) {
    var state = offer.state;
    if(state == 3) {
        console.log("Offer " + offer.id + " was accepted");
        console.log("[Offer #" + offer.id + "] The following items was recieved: ");

       for(var i in itemstoReceive)
         {
           var name = itemsToReceive[i].name;
           console.log(name);
             }}
});