Feature #144
1. Remove code comments from JSON 2. Strip JSONP to become a JSON object
This commit is contained in:
parent
d99d899648
commit
3f8d10daaa
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||
* @version 3.2.0
|
||||
* @date 2015-02-10
|
||||
* @date 2015-02-11
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
|
@ -1481,16 +1481,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
return $1 + '"' + $2 + '"' + $3;
|
||||
});
|
||||
|
||||
//Strips only jQuery's JSONP
|
||||
// if(jsonString.match(/.*jQuery.+?\(/)){
|
||||
// var jsonStringTemp = jsonString.replace(/.*jQuery.+?\(/,'');
|
||||
// jsonString = jsonStringTemp.replace(/\)(?!.*\));?/g,'');
|
||||
// }
|
||||
|
||||
//Clear json's surrounding (for example: 123{"a":"b"}456 => {"a":"b"})
|
||||
jsonString = jsonString.replace(/[^{]*/,'');//remove all characters before first "{" (match first not '{')
|
||||
jsonString.replace(/\*(.|[\r\n])*?\*/g,'');//Remove all code comments
|
||||
|
||||
jsonString = jsonString.replace(/([^}])(?!(.|[\r\n])*(\}))/g,'');//remove all characters after last "}" (match first not '}' which does not have following '}')
|
||||
//If JSON starts with a function (Carachters/digist/"_-"), remove this function.
|
||||
//This is usefull for "stripping" JSONP objects to become JSON
|
||||
//For example: function_12321321 ( [{"a":"b"}] ); => [{"a":"b"}]
|
||||
if(jsonString.match(/[\da-zA-Z_-\s]+\(+\s*/)){
|
||||
var jsonStringTemp = jsonString.replace(/[\da-zA-Z_-\s]+\(+\s*/,'')
|
||||
jsonString = jsonStringTemp.replace(/\s*\)(?!.*[\)])[;\s]*/g,'');
|
||||
}
|
||||
|
||||
return jsonString;
|
||||
};
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -71,16 +71,16 @@ define(function () {
|
|||
return $1 + '"' + $2 + '"' + $3;
|
||||
});
|
||||
|
||||
//Strips only jQuery's JSONP
|
||||
// if(jsonString.match(/.*jQuery.+?\(/)){
|
||||
// var jsonStringTemp = jsonString.replace(/.*jQuery.+?\(/,'');
|
||||
// jsonString = jsonStringTemp.replace(/\)(?!.*\));?/g,'');
|
||||
// }
|
||||
|
||||
//Clear json's surrounding (for example: 123{"a":"b"}456 => {"a":"b"})
|
||||
jsonString = jsonString.replace(/[^{]*/,'');//remove all characters before first "{" (match first not '{')
|
||||
jsonString.replace(/\*(.|[\r\n])*?\*/g,'');//Remove all code comments
|
||||
|
||||
jsonString = jsonString.replace(/([^}])(?!(.|[\r\n])*(\}))/g,'');//remove all characters after last "}" (match first not '}' which does not have following '}')
|
||||
//If JSON starts with a function (Carachters/digist/"_-"), remove this function.
|
||||
//This is usefull for "stripping" JSONP objects to become JSON
|
||||
//For example: function_12321321 ( [{"a":"b"}] ); => [{"a":"b"}]
|
||||
if(jsonString.match(/[\da-zA-Z_-\s]+\(+\s*/)){
|
||||
var jsonStringTemp = jsonString.replace(/[\da-zA-Z_-\s]+\(+\s*/,'')
|
||||
jsonString = jsonStringTemp.replace(/\s*\)(?!.*[\)])[;\s]*/g,'');
|
||||
}
|
||||
|
||||
return jsonString;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue