2021年4月10日星期六

Is there a way to convert [Object] back to a normal object after using JSON.parse()?

I'm using the https://tracker.gg API to make a Discord bot. The problem is when I try to access any of the stats, I just get [Object]. It gives me this error when I try to access stats.kills.displayValue: TypeError: Cannot read property 'displayValue' of undefined. I would like to know if there's a way to convert [Object] back to normal, so I can actually send it's values in a message using the bot.

stats: {        level: [Object],        kills: [Object],        killsAsKillLeader: [Object],        damage: [Object],        headshots: [Object],        timesPlacedtop3: [Object],        carePackageKills: [Object],        rankScore: [Object]      }  
request(options, (err, res, body) => {              if (err) {                  console.log(err);                  message.reply('An error occured!')              }              const parsedData = JSON.parse(body)  
{    data: {      platformInfo: {        platformSlug: 'psn',        platformUserId: 'Daltoosh',        platformUserHandle: 'Daltoosh',        platformUserIdentifier: 'Daltoosh',        avatarUrl: 'https://avatar-cdn.tracker.gg/api/avatar/2/Daltoosh.png',        additionalParameters: null      },      userInfo: {        userId: null,        isPremium: false,        isVerified: false,        isInfluencer: false,        isPartner: false,        countryCode: 'US',        customAvatarUrl: null,        customHeroUrl: null,        socialAccounts: [Array],        pageviews: 4462,        isSuspicious: null      },  
https://stackoverflow.com/questions/67039583/is-there-a-way-to-convert-object-back-to-a-normal-object-after-using-json-pars April 11, 2021 at 05:50AM

没有评论:

发表评论