JSON格式校验
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>JSON格式校验</title>
</head>
<body>
<script type="text/javascript">
let a = {
"age": function() {}
}
function isJson(str) {
try {
JSON.parse(str);
} catch(e) {
return false;
}
return true;
}
console.log(isJson(a))
</script>
</body>
</html>
作者:孟繁贵 Email:meng010387@126.com 期待共同进步!