Skip to content

Instantly share code, notes, and snippets.

@lvxianchao
Created March 2, 2022 00:20
Show Gist options
  • Save lvxianchao/149098571df874c2706d1b30c8178445 to your computer and use it in GitHub Desktop.
Save lvxianchao/149098571df874c2706d1b30c8178445 to your computer and use it in GitHub Desktop.
JS 判断字符串是否是 JSON
function isJson(str) {
if (typeof str === 'string') {
try {
let obj = JSON.parse(str);
return !!(typeof obj === 'object' && obj);
} catch (e) {
return false;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment