js校验字符串是否是json对象

if (value) {
if (typeof value == 'string') {
    try {
      let obj = JSON.parse(value);
      if (typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length) {
        return true;
      } else {
       return false;
      }
    } catch (e) {
       return false;
    }
  }
} else {
 return true;
}

你可能感兴趣的:(js校验字符串是否是json对象)