优化
This commit is contained in:
16
client/shared/utils/json-helper.ts
Normal file
16
client/shared/utils/json-helper.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 判断是否是一个合法的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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user