Hi,
Adding double quotes and escaping string yourself is a hassle.
Strings should also be auto escaped if needed.
Here is my proposed solution.
(it is a bit dirty and might need some work)
replace parse function with:
function parse(str, parsed) {
var res;
var fail = false;
try { res = JSON.parse(str); }
catch (e) { res = null; if(parsed === true){error('JSON parse failed.')}; fail = true;}
if(fail === true && parsed !== true){
var j = $("<div/>").text(str.replace(/\n/g, '\\n'));
j.text(j.html().replace(/"/g, '"'));
var val = j.html();
res = parse('"'+val+'"', true);
}
return res;
}
Now strings will be escaped and quoted automatically.
If the parameter added is an array object string number or bool it still perceived as such.
Only when it can't parse the data it will assume it is a string that needs formatting and escape it automatically.
Hi,
Adding double quotes and escaping string yourself is a hassle.
Strings should also be auto escaped if needed.
Here is my proposed solution.
(it is a bit dirty and might need some work)
replace parse function with:
Now strings will be escaped and quoted automatically.
If the parameter added is an array object string number or bool it still perceived as such.
Only when it can't parse the data it will assume it is a string that needs formatting and escape it automatically.