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

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

返回值为true/false

--->【最简单的方法】js判断字符串是否为JSON格式(20180115更新)

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案