首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解析此输出?

如何解析此输出?
EN

Stack Overflow用户
提问于 2020-09-02 04:35:50
回答 1查看 48关注 0票数 0

如果“已实现:”为真,则我试图输出"name:“元素。这是使用SteamAPI。

它基本上是获取数据并将其存储到“绩效”变量中。

steam.getUserAchievements(id,config.app).then(成就=> { )

我试着做一些像achievements.name这样的事情,但没有成功。

有什么想法吗?

代码语言:javascript
复制
PlayerAchievements {
  steamID: '76561198170684483',
  gameName: 'Deadside',
  achievements: [
    Achievement {
      api: 'DS_FirstStep',
      name: 'First step',
      description: 'Make you first step in game',
      achieved: true,
      unlockTime: 1598449807
    },
    Achievement {
      api: 'DS_Weap_FirstBlood',
      name: 'First blood',
      description: 'Kill an enemy',
      achieved: true,
      unlockTime: 1598451567
    },
    Achievement {
      api: 'DS_Weap_SteelArms',
      name: 'Cold Steel',
      description: 'Kill 10 AI bots with melee weapons',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Weap_Gun',
      name: 'Gunslinger',
      description: 'Kill 100 AI bots with Pistols',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Weap_SMG',
      name: 'Need for Lead',
      description: 'Kill 100 AI bots with SMGs',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Weap_AR',
      name: 'Lead Storm',
      description: 'Kill 100 AI bots with Assault Rifles',
      achieved: true,
      unlockTime: 1598737115
    },
    Achievement {
      api: 'DS_Weap_ShotGun',
      name: 'Son of a Shotgun',
      description: 'Kill 100 AI bots with Shotguns',
      achieved: true,
      unlockTime: 1598755630
    },
    Achievement {
      api: 'DS_Weap_Snip',
      name: 'Rifleman',
      description: 'Kill 100 AI bots with Rifles',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Weap_Gren',
      name: 'Hottest Potato',
      description: 'Kill 10 AI bots with Grenades',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Weap_Headshot',
      name: 'Headshot!',
      description: 'Kill 50 AI bots with headshot',
      achieved: true,
      unlockTime: 1598801600
    },
    Achievement {
      api: 'DS_Weap_LastBullet',
      name: 'Last bullet',
      description: 'Kill 10 AI bots with the last bullet in a clip',
      achieved: true,
      unlockTime: 1598826382
    },
    Achievement {
      api: 'DS_Weap_KillPlayer',
      name: 'There can only One',
      description: 'Kill 10 players',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Weap_AllWeapons',
      name: 'Full Arsenal',
      description: 'Kill one AI bot with each weapon',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_MF_Any',
      name: 'Modder',
      description: 'Put any mod onto a weapon',
      achieved: true,
      unlockTime: 1598456376
    },
    Achievement {
      api: 'DS_Craft_Any',
      name: 'Mr. Fix-It',
      description: 'Craft any item',
      achieved: true,
      unlockTime: 1598450912
    },
    Achievement {
      api: 'DS_Craft_Base',
      name: "A man's home is his castle",
      description: 'Build your first base',
      achieved: true,
      unlockTime: 1598737891
    },
    Achievement {
      api: 'DS_Craft_BreakUp',
      name: 'Field Doctor',
      description: 'Tear any item to rags',
      achieved: true,
      unlockTime: 1598450049
    },
    Achievement {
      api: 'DS_Craft_Lumberjack',
      name: 'Lumberjack',
      description: 'Chop 100 logs',
      achieved: false,
      unlockTime: 0
    },
    Achievement {
      api: 'DS_Trade_Any',
      name: 'Trader',
      description: 'Buy or sell 100 items',
      achieved: true,
      unlockTime: 1598458913
    },
    Achievement {
      api: 'DS_FoodWater_Any',
      name: 'Gourmet',
      description: 'Consume all kinds of food and drinks',
      achieved: false,
      unlockTime: 0
    }
  ]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-02 09:59:56

从您提供的代码中可以看到,PlayerAchievements类有一个数组achievements,其中包含一个Achievement类。

你可以做以下工作来获得成就的名字-

代码语言:javascript
复制
steam.getUserAchievements(id, config.app).then(achievements => {
console.log(achievements.achievements[0].name)
})

它将记录第一个成就名,类似地,您也可以访问其他成就,因为它是一个数组。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63698768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档