Hi,
I am working on a maintenance project and they have used JSON in that project. I am getting the following error Microsoft JScript compilation error: Syntax error in the code snippet. I am new to JSON and after adding watch window I got to know the error and that is expected '(' .But I am not getting the correct syntax.
Following is the code snippet where I am getting the error:
parse : function(jsonString) {
// filter out while statement
var js = jsonString;
if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
return eval('('+js+')');
}
Can anyone help me?
Thanks,
Sheetal
Loading
sheetalPosted Feb 8, 2012, 7:18 AM
whole code is :
var JSON = {
stringify: function stringify(arg) {
var c, i, l, s = '', v;
switch (typeof arg) {
case 'object':
if (arg) {
if (arg.constructor == Array) {
for (i = 0; i < arg.length; ++i) {
v = stringify(arg[i]);
if (s) {
s += ',';
}
s += v;
}
return '[' + s + ']';
} else if (typeof arg.toString != 'undefined') {
for (i in arg) {
v = stringify(arg[i]);
if (typeof v != 'function') {
if (s) {
s += ',';
}
s += stringify(i) + ':' + v;
}
}
return '{' + s + '}';
}
}
return 'null';
case 'number':
return isFinite(arg) ? String(arg) : 'null';
case 'string':
l = arg.length;
s = '"';
for (i = 0; i < l; i += 1) {
c = arg.charAt(i);
if (c >= ' ') {
if (c == '\\' || c == '"') {
s += '\\';
}
s += c;
} else {
switch (c) {
case '\b':
s += '\\b';
break;
case '\f':
s += '\\f';
break;
case '\n':
s += '\\n';
break;
case '\r':
s += '\\r';
break;
case '\t':
s += '\\t';
break;
default:
c = c.charCodeAt();
s += '\\u00' + Math.floor(c / 16).toString(16) +
(c % 16).toString(16);
}
}
}
return s + '"';
case 'boolean':
return String(arg);
case 'function' :
// Added for use of jqGrid T. Tomov
return arg.toString();
default:
return 'null';
}
},
parse : function(jsonString) {
// filter out while statement
var js = jsonString;
if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
return eval('('+js+')');
}
}
and I am getting error on last line: return eval('('+js+')'); as soon as I enter the any number in the textbox.