欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

判断字符串是否为 JSON 格式

最编程 2024-03-27 07:06:39
...
 isJSON(str) {
      if (typeof str === 'string') {
        try {
          let obj = JSON.parse(str);
          if (typeof obj === 'object' && obj) {
            return obj;
          } else {
            return false;
          }
        } catch (error) {
          console.log(error);
          return false;
        }
      }
    },

推荐阅读