Ruby on rails 在JSON的哈希中查找嵌套哈希
我的JSON结构如下所示:Ruby on rails 在JSON的哈希中查找嵌套哈希,ruby-on-rails,ruby,json,Ruby On Rails,Ruby,Json,我的JSON结构如下所示: { "result": { "status": 1, "num_results": 100, "total_results": 500, "results_remaining": 400, "matches": [ { "match_id": 381440228, "match_seq_num": 347730324, "start_time
{
"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
}
]
在这下面会有更多的“匹配”
我想知道的是如何通过“match_id”提取“matches”数组中的一个散列
由于匹配id在散列中,如何通过搜索该值来提取整个散列?一种方法可以是:
hash["result"]["matches"].select {|m| m["match_id"] == match_id }
怎么样
hash["result"]["matches"].find { |m| m["match_id"] == "your id here" }
看