我正在使用以下网址请求方向:
http://maps.googleapis.com/maps/api/directions/json?origin=43.656877,-79.32085&destination=Montreal&sensor=false
然后,谷歌发回一个巨大的 JSON,我想以比这更好的方式访问这些步骤:
response = open("http://maps.googleapis.com/maps/api/directions/json?origin=#{lat1},#{lng1}&destination=#{lat2},#{lng2}&sensor=false").read
response = JSON.parse(response)
response["routes"][0]["legs"][0]["steps"][0]["end_location"]
有没有更漂亮的方式来访问 end_location 而不必使用所有这些数组表示法?我曾想过使用 OpenStruct,但也不理想。