// 安全解析JSON const safeParseJSON = (jsonString) => { try { return JSON.parse(jsonString); } catch (e) { console.error(`JSON解析失败: ${e.message}`, jsonString); return null; // 或返回空对象 {} 根据业务需求 } }; // 安全访问对象属性(支持多级路径) const getNestedValue = (obj, path, fallback = "") => { if (typeof obj !== "object" || obj === null) return fallback; return path.split('.').reduce((acc, key) => { return (acc && acc[key] !== undefined) ? acc[key] : fallback; }, obj); };
客服QQ:1304156118(同微信) 邮箱:lingkouxinxi@qq.com
Copyright © 2015-2024 - 零口网 - 版权所有 -
陕公网安备61011502000040 -
工信部陕ICP备15013078号-1