Created
March 27, 2019 01:54
-
-
Save Jason-cqtan/b76a1ddca4db381851e9b0383d8378bc to your computer and use it in GitHub Desktop.
js querystring转换json
This file contains hidden or 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
function QueryStringToJSON($str) { | |
var pairs = $str.split('&'); | |
var result = {}; | |
pairs.forEach(function(pair) { | |
pair = pair.split('='); | |
result[pair[0]] = decodeURIComponent(pair[1] || ''); | |
}); | |
return JSON.parse(JSON.stringify(result)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment