我使用ruby和谷歌反向geocode yql表,以理想的自动化我有一些搜索查询.我遇到的问题是将查询转换为合法的网址格式.问题是我使用的编码是返回非法的URL.我正在运行的查询如下
query="select * from google.geocoding where q='40.714224,-73.961452'" pQuery= CGI::escape(query)
http://query.yahooapis.com/v1/public/yql?q=select+%2A+from+google.geocoding+where+q%3D%2740.3714224%2C--73.961452%27+format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
唉url是非法的.当检查YQL控制台中查询的样子时,我得到以下内容
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20google.geocoding%20where%20q%3D%2240.714224%2C-73.961452%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
解决方法
如果你想转义一个URI,你应该使用URI :: escape:
require 'uri' URI.escape("select * from google.geocoding where q='40.714224,-73.961452'") # => "select%20*%20from%20google.geocoding%20where%20q='40.714224,-73.961452'"