using try/catch $.parseJSON to check for JSONs

This commit is contained in:
Ganesh Iyer 2017-05-10 17:51:59 -04:00
parent 2a251b219a
commit ce1360f5cb
2 changed files with 12 additions and 16 deletions

View File

@ -629,7 +629,11 @@ function processResponse( xhr ){
data = xhr.responseText; data = xhr.responseText;
} }
}else if( responseText.match(/\s*[\{\[].*/) ){ }else if( responseText.match(/\s*[\{\[].*/) ){
data = $.parseJSON(responseText); try{
data = $.parseJSON(responseText);
} catch(e){
data = responseText;
}
}else{ }else{
data = responseText; data = responseText;
} }

View File

@ -2114,19 +2114,6 @@ function _getSafeElemSize (oElement) {
} }
/*
* @function
* @private
*/
function _isJSON(str){
try{
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
/** /**
* @function * @function
* @private * @private
@ -2141,8 +2128,13 @@ function getTileSourceImplementation( viewer, tileSource, imgOptions, successCal
if ( tileSource.match( /^\s*<.*>\s*$/ ) ) { if ( tileSource.match( /^\s*<.*>\s*$/ ) ) {
tileSource = $.parseXml( tileSource ); tileSource = $.parseXml( tileSource );
//json should start with "{" or "[" and end with "}" or "]" //json should start with "{" or "[" and end with "}" or "]"
} else if ( _isJSON(tileSource) ) { } else if ( tileSource.match(/^\s*[\{\[].*[\}\]]\s*$/ ) ) {
tileSource = $.parseJSON(tileSource); try {
var tileSourceJ = $.parseJSON(tileSource);
tileSource = tileSourceJ;
} catch (e) {
//tileSource = tileSource;
}
} }
} }