mirror of https://github.com/msgbyte/tailchat
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.
17 lines
293 B
TypeScript
17 lines
293 B
TypeScript
4 years ago
|
/**
|
||
|
* 判断是否是一个合法的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;
|
||
|
}
|
||
|
}
|