js判断字符串是否是json格式

function isJSON(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;
        }
    }
}

原文地址

猜你喜欢

转载自blog.csdn.net/weixin_43412413/article/details/103469753