#依赖addressable/uri
require 'addressable/uri'
def _to_query_string(hash)
if hash.instance_of? String
URI.encode hash
else
uri = Addressable::URI.new
uri.query_values = hash
uri.query
end
end
#使用方法:
query_string = _to_query_string( {'name'=>'hello', 'hello'=>'world'} )
puts query_string
#输出:name=hello&pwd=world
query_string = _to_query_string "name=hello&pwd=world"
puts query_string
#输出:name=hello&pwd=world
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
2015小纯洁