Created
December 9, 2010 05:15
-
-
Save fushang318/734367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL query to Hash: | |
Ruby代码 | |
irb(main):012:0> url = "http://javaeye.com?a=1&b=2&c=3#123" | |
=> "http://javaeye.com?a=1&b=2&c=3#123" | |
irb(main):013:0> url = URI.parse(url) | |
=> #<URI::HTTP:0x4cca868 URL:http://javaeye.com?a=1&b=2&c=3#123> | |
irb(main):014:0> url.query | |
=> "a=1&b=2&c=3" | |
irb(main):018:0> Hash[* url.query.split(/[&=]/)] | |
=> {"a"=>"1", "b"=>"2", "c"=>"3"} | |
Hash to URL Query: | |
Ruby代码 | |
hash = {"a"=>"1", "b"=>"2", "c"=>"3"} | |
irb(main):023:0> hash.map{|k_v| k_v.join "="} * "&" | |
=> "a=1&b=2&c=3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment