1

我从 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"
4

1 回答 1

6

使用ArrayEnumerable方法。在这种情况下,找到

data.find { |datum| datum['name'] == 'address' }
# > {"name"=>"address", "value"=>"Mira Internetsolutions ApS Nybovej 19 DK-7500 Holstebro Denmark"}
于 2012-10-01T07:33:46.460 回答