下面是JS判断是否是JSON数据的方法:
具体代码:
function isJSON(str)
{
if (typeof str == 'string')
{
try
{
var obj=JSON.parse(str);
if(typeof obj == 'object' && obj )
{
console.log('是JSON');
return true;
}
else
{
return false;
}
}
catch(e)
{
console.log('error:'+str+'!!!'+e); return false;
}
}
}