A estrutura JSON que tenho é a seguinte:
{
"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
}
]
Haveria muitos mais "jogos" por baixo disso.
O que eu estou querendo saber é como eu iria puxar um dos hashes no array "matches" por seu "match_id".
Já que o match_id está dentro do hash, como eu puxaria o inteira hash procurando por esse valor?
Respostas:
0 para resposta № 1Um caminho poderia ser:
hash["result"]["matches"].select {|m| m["match_id"] == match_id }
0 para resposta № 2
E se
hash["result"]["matches"].find { |m| m["match_id"] == "your id here" }
Vejo Encargável # find.