如何从随机ID的json获取值

时间:2017-07-09 13:11:33

标签: javascript json node.js decode

我在从JSON

中检索值时遇到问题

我不知道如何检索id(随机)后给出的值[NAME]

    "allplayers": {
    "76561197979570214": {
        "clan": "FBÏ",
        "name": "phr",
        "observer_slot": 6,
        "team": "T",
    },
    "76561198156373160": {
        "clan": "ZOWIE",
        "name": "TOAO",
        "observer_slot": 7,
        "team": "T",
    },
    "76561198071702537": {
        "clan": "Team Biceps",
        "name": "snatchie",
        "observer_slot": 8,
        "team": "T",
    },
},

具有常数值

"map": {
    "mode": "competitive",
    "name": "de_overpass",
    "phase": "live",
    "round": 7,
    "team_ct": {
        "score": 7,
        "name": "Team Kinguin",
        "flag": "PL",
        "timeouts_remaining": 1,
        "matches_won_this_series": 0
    },
    "team_t": {
        "score": 0,
        "name": "Samsung4Gamers",
        "flag": "PL",
        "timeouts_remaining": 1,
        "matches_won_this_series": 0
    },
    "num_matches_to_win_series": 0,
    "current_spectators": 3,
    "souvenirs_last_round": 0,
    "souvenirs_total": 0
},

我正在使用

data = JSON.parse(msg);
$("#ct_score").text(data.map.team_ct.score);

任何人都可以帮助我吗?谢谢!

1 个答案:

答案 0 :(得分:0)

您可以遍历结果对象的属性并检查当前属性是否属于它自己,如下所示:



-