【发布时间】:2012-08-03 23:53:50
【问题描述】:
我正在使用 Foursquare API,我想从这个哈希中提取“id”值
[{"id"=>"4fe89779e4b09fd3748d3c5a", "name"=>"Hitcrowd", "contact"=>{"phone"=>"8662012805", "formattedPhone"=>"(866) 201-2805", "twitter"=>"hitcrowd"}, "location"=>{"address"=>"1275 Glenlivet Drive", "crossStreet"=>"Route 100", "lat"=>40.59089895083072, "lng"=>-75.6291255071468, "postalCode"=>"18106", "city"=>"Allentown", "state"=>"Pa", "country"=>"United States", "cc"=>"US"}, "categories"=>[{"id"=>"4bf58dd8d48988d125941735", "name"=>"Tech Startup", "pluralName"=>"Tech Startups", "shortName"=>"Tech Startup", "icon"=>"https://foursquare.com/img/categories/shops/technology.png", "parents"=>["Professional & Other Places", "Offices"], "primary"=>true}], "verified"=>true, "stats"=>{"checkinsCount"=>86, "usersCount"=>4, "tipCount"=>0}, "url"=>"http://www.hitcrowd.com", "likes"=>{"count"=>0, "groups"=>[]}, "beenHere"=>{"count"=>0}, "storeId"=>""}]
当我尝试使用['id'] 提取它时,我收到此错误can't convert Symbol into Integer。如何使用 ruby 提取值?另外,对于每次提取“id”值的多个哈希,我该怎么做?
请原谅我的经验不足。谢谢!
【问题讨论】:
-
看起来这是一个有一个值的数组,一个哈希值。
yourobject.first['id']有效吗?
标签: ruby json api parsing hash