node-fs (1) can not be read from the file to the internal flow is converted into a string of json

The first piece of code

fs = the require the let ( 'fs' ); // fs module incorporated 
the let BLOB = fs.readFileSync ( '/ Node / Product1 / data.txt' ); // read the files in the specified directory
 IF (BLOB [0] = BLOB 0xEF && == [. 1] && 0xBB BLOB === [2] === 0xBF ) {// removing special characters, symbols so that these data can not be resolved 
  BLOB = blob.slice (. 3 ); 
} 
the let STR = BLOB .toString ( 'UTF-. 8' ); // specify the encoding 
console.log (JSON.parse (str));

 

The reason for this is because the editor Notepad tool when manually saving will try to be smart to do some processing of the data, the data appears to be correct, but it can not be resolved, a few more characters can not see unicod

Reproduced in: https: //www.cnblogs.com/wrhbk/p/11076044.html

Guess you like

Origin blog.csdn.net/weixin_34310127/article/details/93508991