Follow Us

Embarassing ExtJS Ext.util.JSON.decode() method not properly implemented

extjs

In this case, you will need to manually catch the error, with a

try { 
Ext.util.JSON.decode(someJSONstring);
}
catch (e) {
//whatever you want to do here, the JSON string is incorrectly formatted...
} structure.

Or you could override the Ext.util.JSON.decode() method with something like

(function() {
var oldDc = Ext.util.JSON.decode;
if (oldDc.toString().indexOf("safe") === -1) {
Ext.util.JSON.decode = function(someJSONstring, safe) {
if (!safe) {
return oldDc(someJSONstring);
} else {
try{
return oldDc(someJSONstring);
}catch(e){
return null;
}
}
};
Ext.decode = Ext.util.JSON.decode;
}
}());