打赏

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>

 

posted @ 2018-09-17 17:56  孟繁贵  阅读(4947)  评论(0编辑  收藏  举报
TOP