Skip to content

Instantly share code, notes, and snippets.

@Jason-cqtan
Created March 27, 2019 01:54
Show Gist options
  • Save Jason-cqtan/b76a1ddca4db381851e9b0383d8378bc to your computer and use it in GitHub Desktop.
Save Jason-cqtan/b76a1ddca4db381851e9b0383d8378bc to your computer and use it in GitHub Desktop.
js querystring转换json
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