HarmonyOS 鸿蒙Next写入JSON文件时数据出现错误
HarmonyOS 鸿蒙Next写入JSON文件时数据出现错误
export function createConfig(): void { let config: Config = { loginInfo: { server: ‘’, username: ‘’, password: ‘’ }, autoLogin: false, jumpTime: 10 } // fs.unlinkSync(filesDir + ‘/config.json’) let configStatus = fs.accessSync(filesDir + ‘/config.json’) if (configStatus === true) { console.log(“配置文件存在。”) } else { console.log(“配置文件不存在。”) let file = fs.openSync(filesDir + ‘/config.json’, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); fs.writeSync(file.fd, JSON.stringify(config)); fs.closeSync(file); } console.log(“配置文件位置”, filesDir + ‘/config.json’) }
export function readConfig(): Config { let config: Config let file = fs.openSync(filesDir + ‘/config.json’, fs.OpenMode.READ_WRITE) let arrayBuffer = new ArrayBuffer(4096); let readLen = fs.readSync(file.fd, arrayBuffer); let buf = buffer.from(arrayBuffer, 0, readLen); config = JSON.parse(buf.toString()) console.log(“读取配置”, JSON.stringify(config)) fs.closeSync(file); return config }
createConfig() config = readConfig()
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
这样创建文件然后写入,再读取出来,结果变成了{“loginInfo”:{“server”:"",“username”:"",“password”:""},“a4”:false,“jumpTime”:10}
为什么autoLogin会变成a4?换成其他的比如remember也是一样,偶尔好像还会变成a5,为什么其他的就不会变?
更多关于HarmonyOS 鸿蒙Next写入JSON文件时数据出现错误的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
希望HarmonyOS能继续加强在安全性方面的研发,保护用户的隐私和数据安全。
更多关于HarmonyOS 鸿蒙Next写入JSON文件时数据出现错误的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17