0

The JSON structure I have is as follows:

{
"result": {
    "status": 1,
    "num_results": 100,
    "total_results": 500,
    "results_remaining": 400,
    "matches": [
        {
            "match_id": 381440228,
            "match_seq_num": 347730324,
            "start_time": 1384292236,
            "lobby_type": 0
        },
        {
            "match_id": 380304327,
            "match_seq_num": 346687624,
            "start_time": 1384203633,
            "lobby_type": 0
        }
                    ]

There would be many more "matches" underneath that.

What I'm wondering is how I would pull one of the hashes in the 'matches' array by its 'match_id'.

Since the match_id is inside the hash, how would I pull the entire hash by searching for that value?

4

2 回答 2

0

怎么样

hash["result"]["matches"].find { |m| m["match_id"] == "your id here" }

请参阅Enumberable#find

于 2013-11-13T18:59:00.207 回答
0

一种方法可能是:

hash["result"]["matches"].select {|m| m["match_id"] == match_id }
于 2013-11-13T18:58:47.787 回答