dnagir ha scritto:
Unfortunately I do not see jQuery providing similar function, while
Prototype does:
http://www.prototypejs.org/api/string/isJSON
I've found in the source the function you've linked above, I've rewrited to make it works with jquery:

jQuery.isJson = function(str) {
   if (jQuery.trim(str) == '') return false;
   str = str.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str); }


After including this piece of code (after jquery source), you can call :

$.isJson(mystring);

Bye :-)

--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482

Reply via email to