【jQuery】jQuery/js 判断字符串是否JSON字符串

今日份代码:

        isJSON: function(str) {
            if (typeof str == 'string') {
                try {
                    var obj=JSON.parse(str);
                    if(typeof obj == 'object' && obj ){
                        return true;
                    }else{
                        return false;
                    }

                } catch(e) {
                    return false;
                }
            }else if (typeof str == 'object'  && str) {
                return true;
            }
        },
原文地址:https://www.cnblogs.com/sxdcgaq8080/p/13210474.html