gpt4 book ai didi

javascript - 节点 : How to preserve "\u00a0" in JSON string during a merge with other JSON

转载 作者:行者123 更新时间:2023-11-29 10:01:03 27 4
gpt4 key购买 nike

<分区>

我必须合并 2 个 json 文件,并且需要在其中一个文件中保留一个字符串:

“周”:“weeks\u00a0days”

合并后的 \u00a0 始终更改为空格:"weeks": "weeks days"

我希望它保持为:"weeks": "weeks\u00a0days"

一些代码:

//merge.js
const fs = require('fs');
const test1 = fs.readFileSync('./test1.json', 'utf8');
const test2 = fs.readFileSync('./test2.json', 'utf8');

const merge = (obj1, obj2) =>
JSON.stringify({ ...JSON.parse(obj1), ...JSON.parse(obj2) }, null, 4);

const saveFile = (fileName, obj1, obj2) => {
fs.writeFile(`${__dirname}/${fileName}`, merge(obj1, obj2), err => {
if (err) throw err;
console.log(`The file ${fileName} has been saved!`);
});
};

saveFile('testFinal.json', test1, test2);

test1.json

{
"link": {
"about": "About",
"version": "version"
},
"items": {
"siteId": "Site ID",
"siteName": "Site name",
"siteType": "Site type",
"weeks": "weeks\u00a0days"
}
}

test2.json

{
"features": {
"activateFeatures": "Activate features",
"confirmation": "Confirmation",
"hardware": "Hardware",
"existingHardware": "Existing hardware",
"emailLicense": "Email license",
"downloadLicense": "Select quantity"
}
}

请帮忙

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com