我将以我现在是一年级学生的身份对Java和整个编程领域感到陌生,以此开始这个问题的开头。我正在尝试创建一个利用API提供给我的数据的应用。但是,此API仅将数据作为带有不同子节的整个String返回。
这是返回记录后的样子:
User {
id: 'redacted',
username: 'Despacito II',
platform: 'PC',
url: 'https://fortnitetracker.com/profile/pc/Despacito II',
stats:
{ solo:
Mode {
score: 101032,
kd: 0.35,
matches: 916,
kills: 324,
kills_per_match: 0.35,
score_per_match: 110.3,
wins: 1,
top_3: 1,
top_5: 2,
top_6: 4,
top_12: 8,
top_25: 231 },
duo:
Mode {
score: 29650,
kd: 0.47,
matches: 198,
kills: 92,
kills_per_match: 0.46,
score_per_match: 149.75,
wins: 2,
top_3: 2,
top_5: 23,
top_6: 27,
top_12: 104,
top_25: 158 },
squad:
Mode {
score: 166404,
kd: 0.42,
matches: 795,
kills: 323,
kills_per_match: 0.41,
score_per_match: 209.31,
wins: 31,
top_3: 120,
top_5: 151,
top_6: 488,
top_12: 790,
top_25: 1580 },
current_solo:
Mode {
score: 16660,
kd: 0.62,
matches: 128,
kills: 80,
kills_per_match: 0.62,
score_per_match: 130.16,
wins: 0,
top_3: 0,
top_5: 0,
top_6: 0,
top_12: 0,
top_25: 34 },
current_duo:
Mode {
score: 11907,
kd: 0.78,
matches: 60,
kills: 45,
kills_per_match: 0.75,
score_per_match: 198.45,
wins: 2,
top_3: 2,
top_5: 12,
top_6: 16,
top_12: 55,
top_25: 87 },
current_squad:
Mode {
score: 24822,
kd: 0.56,
matches: 130,
kills: 70,
kills_per_match: 0.54,
score_per_match: 190.94,
wins: 4,
top_3: 19,
top_5: 23,
top_6: 69,
top_12: 115,
top_25: 230 },
lifetime:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } }
我想知道如何获取此返回值并从中获取变量。例如,是否有一个名为“ kdSolo”的新变量,并且根据API返回值是否等于0.35?
我也很想知道是否有一个特定的术语以及它的含义,以供将来参考和研究。再次抱歉noobie问题。
答案 0 :(得分:0)
如果您要walk
当前的对象树,则只需执行以下操作:
var kdSolo = User.stats.solo.Mode.kd
// kdSolo will now be 0.35
我问有关JSON的原因是因为上面的内容不是有效的JSON对象。