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' }