我从Ripe获得了这个JSON输出。
[
{"name"=>"organisation", "value"=>"ORG-MI1-RIPE"},
{"name"=>"org-name", "value"=>"Mira Internetsolutions ApS"},
{"name"=>"org-type", "value"=>"LIR"},
{"name"=>"address", "value"=>"Mira Internetsolutions ApS Nybovej 19 DK-7500 Holstebro Denmark"},
{"name"=>"phone", "value"=>"+45 9610 1510"},
{"name"=>"fax-no", "value"=>"+45 9610 1511"},
{"name"=>"admin-c", "value"=>"MIA3-RIPE", "referenced-type"=>"person-role", "link"=>{"xlink:type"=>"locator", "xlink:href"=>"http://apps.db.ripe.net/whois/lookup/ripe/person-role/MIA3-RIPE"}},
{"name"=>"admin-c", "value"=>"MIA3-RIPE", "referenced-type"=>"person-role", "link"=>{"xlink:type"=>"locator", "xlink:href"=>"http://apps.db.ripe.net/whois/lookup/ripe/person-role/MIA3-RIPE"}},
{"name"=>"mnt-ref", "value"=>"rh-mira", "referenced-type"=>"mntner", "link"=>{"xlink:type"=>"locator", "xlink:href"=>"http://apps.db.ripe.net/whois/lookup/ripe/mntner/rh-mira"}},
{"name"=>"mnt-ref", "value"=>"RIPE-NCC-HM-MNT", "referenced-type"=>"mntner", "link"=>{"xlink:type"=>"locator", "xlink:href"=>"http://apps.db.ripe.net/whois/lookup/ripe/mntner/RIPE-NCC-HM-MNT"}},
{"name"=>"mnt-by", "value"=>"RIPE-NCC-HM-MNT", "referenced-type"=>"mntner", "link"=>{"xlink:type"=>"locator", "xlink:href"=>"http://apps.db.ripe.net/whois/lookup/ripe/mntner/RIPE-NCC-HM-MNT"}},
{"name"=>"source", "value"=>"RIPE", "comment"=>"Filtered"}
]
我不能每次都依赖于它。我有大约200,000个IP要检查。我该如何搜索:
"name" => "address"
然后得到:
"value" => "Mira Internetsolutions ApS Nybovej 19 DK-7500 Holstebro Denmark"
答案 0 :(得分:6)
使用Array和Enumerable方法。在这种情况下,find:
data.find { |datum| datum['name'] == 'address' }
# > {"name"=>"address", "value"=>"Mira Internetsolutions ApS Nybovej 19 DK-7500 Holstebro Denmark"}