Method Description:
Turns the string into an object. In fact, the URL with the parameter string to the array of objects. (see examples to know)
Grammar:
Copy Code code as follows:
Querystring.parse (str, [Sep], [eq], [options])
Receive parameters:
STR wants to convert string
Sep set Separator, default to ' & '
EQ set assignment, default to ' = '
[Options] Maxkeys can accept the maximum length of a string, default to 1000
Example:
Copy Code code as follows:
Querystring.parse (' Foo=bar&baz=qux&baz=quux&corge ')
Returns
{foo: ' Bar ', Baz: [' Qux ', ' Quux '], Corge: '}
Source:
Copy Code code as follows:
Parse a key=val string.
Querystring.parse = Querystring.decode = function (qs, Sep, eq, options) {
Sep = Sep | | ' & ';
eq = EQ | | '=';
var obj = {};
if (!util.isstring (qs) | | qs.length = = 0) {
return obj;
}
var regexp =/\+/g;
QS = qs.split (Sep);
var maxkeys = 1000;
if (Options && util.isnumber (Options.maxkeys)) {
Maxkeys = Options.maxkeys;
}
var len = qs.length;
Maxkeys <= 0 means that we should not limit keys count
if (Maxkeys > 0 && len > Maxkeys) {
len = Maxkeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace (regexp, '%20 '),
IDX = X.indexof (eq),
Kstr, Vstr, K, V;
if (idx >= 0) {
KSTR = x.substr (0, IDX);
VSTR = x.substr (idx + 1);
} else {
KSTR = x;
Vstr = ';
}
try {
K = decodeURIComponent (KSTR);
v = decodeuricomponent (VSTR);
catch (e) {
K = Querystring.unescape (Kstr, true);
v = Querystring.unescape (Vstr, true);
}
if (!hasownproperty (obj, k)) {
Obj[k] = v;
else if (Util.isarray (Obj[k])) {
Obj[k].push (v);
} else {
OBJ[K] = [obj[k], V];
}
}
return obj;
};