(obj)
| 237 | |
| 238 | // ─── 深度解包嵌套 JSON 字符串 ────────────────────────────── |
| 239 | export function deepParseJSONStrings(obj) { |
| 240 | if (Array.isArray(obj)) { |
| 241 | return obj.map((item) => { |
| 242 | if (typeof item === 'string' && item.trim()) { |
| 243 | try { |
| 244 | const parsed = JSON.parse(item); |
| 245 | if (_isDeepParsable(parsed)) { |
| 246 | return deepParseJSONStrings(parsed); |
| 247 | } |
| 248 | } catch (_) {} |
| 249 | } |
| 250 | return deepParseJSONStrings(item); |
| 251 | }); |
| 252 | } |
| 253 | if (typeof obj === 'object' && obj !== null) { |
| 254 | const newObj = {}; |
| 255 | for (const key of Object.keys(obj)) { |
| 256 | const val = obj[key]; |
| 257 | if (typeof val === 'string' && val.trim()) { |
| 258 | try { |
| 259 | const parsed = JSON.parse(val); |
| 260 | if (_isDeepParsable(parsed)) { |
| 261 | newObj[key] = deepParseJSONStrings(parsed); |
| 262 | continue; |
| 263 | } |
| 264 | } catch (_) {} |
| 265 | } |
| 266 | newObj[key] = deepParseJSONStrings(val); |
| 267 | } |
| 268 | return newObj; |
| 269 | } |
| 270 | return obj; |
| 271 | } |
| 272 | |
| 273 | export function unpackTopLevelEscapedJSON(value) { |
| 274 | if (typeof value !== 'string' || !value.trim()) return value; |
no test coverage detected