【.cmd】 バッチファイルスクリプト %15 【.bat】at TECH
【.cmd】 バッチファイルスクリプト %15 【.bat】 - 暇つぶし2ch285:デフォルトの名無しさん
23/05/10 03:43:26.68 fIRqc6o3.net
>>264
Ruby なら、

require 'json'

# 改行を削除する。削除しなくても同じ結果
input_json_str = <<'JSON'.delete( "\n" )
[{"ID": 1,"Level": 50, "Status": {"idx":1}},
{"ID": 1,"Level": 100, "Status": {"idx":2}},
{"ID": 2,"Level": 50, "Status": {"idx":3}},
{"ID": 3,"Level": 50, "Status": {"idx":4}},
{"ID": 3,"Level": 100, "Status": {"idx":5}}]
JSON

input_json_obj = JSON.parse( input_json_str )

# ID でグループ化して、最大Level のものを取得する
result = input_json_obj.group_by { |hash| hash[ "ID" ] }.map do |row|
row[ 1 ].max_by { |hash| hash[ "Level" ] }
end

p result

出力
[ {"ID"=>1, "Level"=>98, "Status"=>{"idx"=>2}},
{"ID"=>2, "Level"=>48, "Status"=>{"idx"=>3}},
{"ID"=>3, "Level"=>98, "Status"=>{"idx"=>5}} ]


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch