zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js判断字符串是否json格式

JSJSONJSON 字符串 判断 是否 格式
2023-09-14 08:56:58 时间
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) {
            console.log('error:'+str+'!!!'+e);
            return false;
        }
    }
    console.log('It is not a string!')
}