从JSON输出获取字符串

时间:2019-01-25 20:21:18

标签: javascript node.js json discord.js

如何从.p中获取.largeImage

Game {
  name: 'Spotify',
  type: 2,
  url: null,
  details: 'Promises (with Sam Smith)',
  state: 'Calvin Harris; Sam Smith; Jessie Reyez',
  applicationID: null,
  timestamps:
   { start: 2019-01-25T19:58:17.089Z,
     end: 2019-01-25T20:01:50.398Z },
  party: { id: 'spotify:365162284655443978' },
  assets:
   RichPresenceAssets {
     largeText: 'Promises (with Sam Smith)',
     smallText: null,
     largeImage: 'spotify:b0875765de11e1b6bdfbdd07c2de72e65c02f524',
     smallImage: null },
  syncID: '5N5k9nd479b1xpDZ4usjrg',
  _flags: 48 }
RichPresenceAssets {
  largeText: 'Promises (with Sam Smith)',
  smallText: null,
  largeImage: 'spotify:b0875765de11e1b6bdfbdd07c2de72e65c02f524',
  smallImage: null }

我尝试过

 Game.assets.RichPresenceAssets.largeImage

但是那是undefined

所以现在该怎么办,我找不到要使用的东西,或者该怎么做才能使其正常工作。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我认为这应该可行:

assets.largeImage

yourGameVariable.assets.largeImage

应使用包含给定转储的变量替换yourGameVariable

似乎您从dev-tools控制台粘贴了转储。您可以使用JSON.stringify来获取有效的JSON。

我想GameRichPresenceAssets只是类名。