私が持っているJSON構造は次のとおりです。
{
"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
}
]
その下にはもっとたくさんの「マッチ」があるでしょう。
私が疑問に思っているのは、 "matches"配列内のハッシュの1つをその "match_id"でどのように引っ張るかです。
match_idはハッシュの内側にあるので、どのように私は引きますか 全体 その値を検索してハッシュ?
回答:
回答№1は01つの方法があります:
hash["result"]["matches"].select {|m| m["match_id"] == match_id }
回答№2の場合は0
いかがですか
hash["result"]["matches"].find { |m| m["match_id"] == "your id here" }
見る Enumberable#find.