This commit is contained in:
zw199166
2026-01-22 14:34:38 +08:00
parent 6ee8ce42ed
commit 1f3a3ca8bb
234 changed files with 5534 additions and 2395 deletions

View File

@@ -43,6 +43,35 @@ export async function uploadImgs(paths, success)
}
}
export function isValidJSON(jsonString) {
// 先做基础类型校验,排除非字符串的情况
if (typeof jsonString !== 'string') {
console.warn('输入必须是字符串类型');
return false;
}
// 去除首尾空白字符(可选,但能兼容常见的格式问题)
jsonString = jsonString.trim();
// 空字符串直接判定为无效
if (jsonString === '') {
return false;
}
try {
// 尝试解析 JSON 字符串
const parsed = JSON.parse(jsonString);
// 额外校验:确保解析结果是对象/数组(排除单个数字/布尔值等非结构化 JSON
// 如果不需要这个校验,可以删除下面这行
if (typeof parsed !== 'object' || parsed === null) return false;
return true;
} catch (error) {
// 解析失败,说明格式错误
console.log('JSON 格式错误:', error.message);
return false;
}
}
export function accDiv(arg1,arg2){
var t1=0,t2=0,r1,r2;
try{t1=arg1.toString().split(".")[1].length}catch(e){}