我有一個JSON File看起來像:轉換Json的結構(JSON文件)到Ruby哈希
{"business_id": "vcNAWiLM4dR7D2nwwJ7nCA", "full_address": "4840 E Indian School Rd\nSte 101\nPhoenix, AZ 85018", "hours": {"Tuesday": {"close": "17:00", "open": "08:00"}, "Friday": {"close": "17:00", "open": "08:00"}, "Monday": {"close": "17:00", "open": "08:00"}, "Wednesday": {"close": "17:00", "open": "08:00"}, "Thursday": {"close": "17:00", "open": "08:00"}}, "open": true, "categories": ["Doctors", "Health & Medical"], "city": "Phoenix", "review_count": 7, "name": "Eric Goldberg, MD", "neighborhoods": [], "longitude": -111.98375799999999, "state": "AZ", "stars": 3.5, "latitude": 33.499313000000001, "attributes": {"By Appointment Only": true}, "type": "business"}
{"business_id": "JwUE5GmEO-sH1FuwJgKBlQ", "full_address": "6162 US Highway 51\nDe Forest, WI 53532", "hours": {}, "open": true, "categories": ["Restaurants"], "city": "De Forest", "review_count": 26, "name": "Pine Cone Restaurant", "neighborhoods": [], "longitude": -89.335843999999994, "state": "WI", "stars": 4.0, "latitude": 43.238892999999997, "attributes": {"Take-out": true, "Good For": {"dessert": false, "latenight": false, "lunch": true, "dinner": false, "breakfast": false, "brunch": false}, "Caters": false, "Noise Level": "average", "Takes Reservations": false, "Delivery": false, "Ambience": {"romantic": false, "intimate": false, "touristy": false, "hipster": false, "divey": false, "classy": false, "trendy": false, "upscale": false, "casual": false}, "Parking": {"garage": false, "street": false, "validated": false, "lot": true, "valet": false}, "Has TV": true, "Outdoor Seating": false, "Attire": "casual", "Alcohol": "none", "Waiter Service": true, "Accepts Credit Cards": true, "Good for Kids": true, "Good For Groups": true, "Price Range": 1}, "type": "business"}
我想遍歷這個文件,個體結構轉換成一個Ruby散列,這樣我可以訪問不同哈希來對它們執行操作。
這是JSON文件的第一個結構的哈希:
{"business_id"=>"uUsfpN81JCMKyH6c0D0bTg", "full_address"=>"1910 Village Center Cir\nSte 6\nSummerlin\nLas Vegas, NV 89134", "hours"=>{}, "open"=>true, "categories"=>["Food", "Desserts", "Italian", "Pizza", "Restaurants"], "city"=>"Las Vegas", "review_count"=>6, "name"=>"Rocco's NY Pizza & Pasta", "neighborhoods"=>["Summerlin"], "longitude"=>-115.3041999, }
同樣地,我想擁有所有其他JSON結構的哈希值。我如何在Ruby on Rails中做到這一點?
請勿使用鏈接指向回答您的問題所需的數據。當你的問題中的鏈接腐爛集合將變成無稽之談,因爲沒有人能夠告訴你正在談論什麼數據。相反,應提供最小數量的樣本數據,儘可能小以重現問題。 – 2014-11-05 20:08:55