From ce70fd98ec6ef38a6dfc377235576cd533d2fca8 Mon Sep 17 00:00:00 2001 From: gcw_IJ7DAiVL Date: Wed, 15 Oct 2025 09:27:20 +0800 Subject: [PATCH] =?UTF-8?q?add=20json=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/home/home.vue | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/views/home/home.vue b/src/views/home/home.vue index 1db1142..2d1f45b 100644 --- a/src/views/home/home.vue +++ b/src/views/home/home.vue @@ -2549,14 +2549,16 @@ export default { handleExportJosn() { this.dialogJsonVisible = true }, - decodeEscapedJson(str) { - // 去掉最外层的转义引号 - str = str.slice(1, -1); - // 循环解码,直到字符串不再包含转义字符 - while (str.includes('\\')) { - str = JSON.parse('"' + str + '"'); + decodeEscapedJson(str) { + // 去掉字符串首尾的空白字符 + str = str.trim(); + // 直接解析 JSON 字符串 + try { + return JSON.parse(str); + } catch (e) { + console.error('Error parsing JSON:', e); + return null; } - return str }, handleJson() { this.jsonLoading = true @@ -2573,7 +2575,7 @@ export default { .then(response => { this.jsonInfo = { path: response.data.path, - json: this.decodeEscapedJson(response.data.json) + json: JSON.stringify(response.data.json, null, 2) } this.jsonLoading = false }) @@ -2592,7 +2594,7 @@ export default { .then(response => response.text()) .then(text => { const parsedData = iniParser.parse(text); - axios.post(`http://${parsedData.http.address}:${parsedData.http.port}/api/json/save?path=${this.jsonInfo.path}`, JSON.stringify(this.jsonInfo.json), { + axios.post(`http://${parsedData.http.address}:${parsedData.http.port}/api/json/save?path=${this.jsonInfo.path}`, JSON.stringify(JSON.parse(this.jsonInfo.json)), { headers: { 'Content-Type': 'application/json' }