判断是否是json字符串

it2023-05-08  75

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

} catch (e) { console.log('error:' + str + '!!!' + e); return false; } } console.log('It is not a string!')

}

最新回复(0)