输入字符串的格式是 a=1&b=2&c=3
$.par2Json = function (string, overwrite) {
var obj = {}, pairs = string.split('&'), d = decodeURIComponent, name, value;
$.each(pairs, function (i, pair) {
pair = pair.split('=');
name = d(pair[0]);
value = d(pair[1]);
obj[name] = value;
});
return obj;
};
var test=$.par2Json('a=1&b=2&c=3');
console.log(test);
//Object {a: "1", b: "2", c: "3"}
json对象转行json字符串:
var jsonObj=JSON.stringify(test);
json字符串转json对象
JSON.parse(jsonObj);