Date: 2009dec22
Language: javaScript
Q. How can I safely parse JSON in any browser?
A. Many browsers have a JSON.parse() function which is the best thing
to use. But not all. So use this function:
function parseJson(json) {
var out;
try
{
if (typeof JSON == 'object' && typeof JSON.parse == 'function') {
out = JSON.parse(json);
}
else {
out = eval('('+json+')');
}
}
catch(e) {
// do nothing
}
return out;
}
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment