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!’)
}
【最简单的方法】js判断字符串是否为JSON格式
最新推荐文章于 2024-06-07 10:14:15 发布