You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/utils/json-helper.ts

17 lines
293 B
TypeScript

/**
* 判断是否是一个合法的json字符串
* @param jsonStr json字符串
*/
export function isValidJson(jsonStr: string): boolean {
if (typeof jsonStr !== 'string') {
return false;
}
try {
JSON.parse(jsonStr);
return true;
} catch (e) {
return false;
}
}