Hash转换为查询字符串
- 作者: 2015小纯洁
- 来源: 51数据库
- 2022-08-12
#依赖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
推荐阅读