Skip to content

Instantly share code, notes, and snippets.

@dasDaniel
Created October 27, 2013 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasDaniel/7176323 to your computer and use it in GitHub Desktop.
Save dasDaniel/7176323 to your computer and use it in GitHub Desktop.
deparam javascript split serialized string with square bracket items. ref http://jsfiddle.net/drzaus/8EE8k/
deparam = (function(d,x,params,pair,i) {
return function (qs) {
params = {};
// remove preceding non-querystring, correct spaces, and split
qs = qs.substring(qs.indexOf('?')+1).replace(x,' ').split('&');
// march and parse
for (i = qs.length; i > 0;) {
pair = qs[--i].split('=');
//params[d(pair[0])] = d(pair[1]);
var ar = d(pair[0]).match(/\[(.*?)\]/g);
for (var j = 0; j < ar.length; j++) {
ar[j] = ar[j].replace("\[", "");
ar[j] = ar[j].replace("\]", "");
}
if(typeof params[ar[0]] == 'undefined'){params[ar[0]]= {};}
params[ar[0]][ar[1]] = d(pair[1]);
// console.log(ar);
}
return params;
};//-- fn deparam
})(decodeURIComponent, /\+/g);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment