我可以从字符串中获取一个数组
http_params="created_end_date=2013-02-28&created_start_date=2013-01-01&page_size=50&offset=0&order_id=0D1108211501118%0D%0A0D11108211501118%0D%0Ac%0D%0AD%0D%0ADK212071409743%0D%0AKK30109110100%0D%0AKK30111140300%0D%0AKK30111140400%0D%0AKK30115120100%0D%0AKK30115150100&page_number=1"
所以我做了myarray=http_params.split("&")
:
myarray=["created_end_date=2013-02-28", "created_start_date=2013-01-01", "page_size=50", "offset=0", "order_id=0D1108211501118%0D%0A0D11108211501118%0D%0Ac%0D%0AD%0D%0ADK212071409743%0D%0AKK30109110100%0D%0AKK30111140300%0D%0AKK30111140400%0D%0AKK30115120100%0D%0AKK30115150100", "page_number=1"]
我需要将其转换为哈希 myhash,以便我可以对 myhash.to_json 进行 Rest Client 发布调用。基本上它应该是键值对,例如:
{:created_end_date=>"2013-02-28",:created_start_date=>"2013-01-01"....}
我知道逆运算可以这样完成:
http_params = myhash.map{|k,v| "#{k}=#{v}"}.join('&')
但我无法为此提供简洁的代码。
我应该怎么做?