3
Well, I have a file JSON where all the symbols Unicode as this " " are in this format: "u2605" has some way to convert these codes to the symbols when my program Nodejs read the JSON?
Example of how it is: {"name":"\u2605 Bayonet","price":15713,"have":6,"max":6}
Example of how I want it to stay: {"name":"★ Bayonet","price":15713,"have":6,"max":6}
I even manually made one replace for these codes, but when I run it repeats twice the JSON giving replace only the first time and does not store in the variable the JSON altered.
My code:
Trade.prototype.getSteamapis = function getSteamapis(callback) {
fs.readFile(`./prices/730.json`,'utf8',function (err,body) {
if (err) {
return console.log(err);
}
body.replace("/\u2605/g","★")
body.replace("/\u2605 /g","★")
body.replace("/\u9f8d/g","龍")
body.replace("/\u58f1/g","壱")
body.replace("/\u2122/g","™")
body.replace("/\u5f10/g","弐")
body.replace("/\u738b/g","王")
console.log(body)
return body
});
})
}
Not that it’ll solve for your case, but when you do the
replace
must assign to the variable:body = body.replace("/\u2605/g","★");
. And one more thing: Make sure that the files are no longer being saved with the code and theNode.js
is reading correctly?– Sorack
well yes I found an error at the time of reading, but he only showed me that the raplace is not working :[
– Luciandro Francisco Júnior