0

I'm trying to get app_data because this holds other data that I need, such as quality, but every time I try to log app_data it comes up with undefined, logging itemJson works fine?

Code

function getBPPrice(item, itemJson){
     console.log(itemJson);
     console.log(itemJson.app_data);
     console.log(itemJson.app_data.quality);
     console.log(Prices.response.items[item].prices[itemJson.app_data.quality][itemJson.tradable].Craftable[0].value);
}

and

var item = theirItems[i].market_name;
var itemJson = JSON.stringify(theirItems[i], null, 4);

getBPPrice(item, itemJson);

Now, console.log(itemJson); works as I've stated before, but console.log(itemJson.app_data); just outputs undefined, so the next output which is the quality value doesn't work.

Json

https://pastebin.com/cFSd6GLU

Pastebin link because it is quite long, app_data is near the bottom too.

Edit:

Error i get -

undefined C:\Users\datpe\Desktop\d\bot.js:89 console.log(itemJson.app_data.quality); ^

TypeError: Cannot read property 'quality' of undefined at getBPPrice (C:\Users\datpe\Desktop\d\bot.js:89:32) at processOffer (C:\Users\datpe\Desktop\d\bot.js:136:4) at TradeOfferManager.manager.on (C:\Users\datpe\Desktop\d\bot.js:189:2) at emitOne (events.js:115:13) at TradeOfferManager.emit (events.js:210:7) at received.forEach (C:\Users\datpe\node_modules\steam-tradeoffer-manager\lib\polling.js:235:10) at Array.forEach (native) at getOffers (C:\Users\datpe\node_modules\steam-tradeoffer-manager\lib\polling.js:219:12) at Helpers.checkNeededDescriptions (C:\Users\datpe\node_modules\steam-tradeoffer-manager\lib\index.js:483:4) at Async.map (C:\Users\datpe\node_modules\steam-tradeoffer-manager\lib\assets.js:171:4)

1
  • 1
    Second argument to JSON.stringify() is a "replacer". If you are simply after "pretty printing" without modification then you want undefined there instead, since that's least likely to actually match anything ( since undefined is not really a JSON output thing ). But you can't access a property from a string, so you seem to have a couple of concepts wrong here. Commented Oct 22, 2017 at 21:42

1 Answer 1

2

It's not 100% clear what you are trying to do here, but it looks like you have an an array theirItems and each member of theirItems is an object that you want. But when you do this…

var itemJson = JSON.stringify(theirItems[i], null, 4);

itemJson is now a string representing the object you want, not the object itself. You can't then access individual elements of the object like:

itemJson.app_data

because its a string, not the actual object.

I think what you want to do is simply grab the object itself and pass that to your function:

var itemJson = theirItems[i]
// then pass the actual object:
getBPPrice(item, itemJson);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.