这给我带来了json文件的所有值
例子:我有id,name和lastname,我想带上id值
fs.readFile("user.json", function (err, data) {
if (err) throw err;
console.log(data.toString());
});
信息文件json
{"Identificador":0,"Nombre_Principal":"man","Nombre_Paterno":"man","Nombre_Materno":"man","Contrasena":"man","Correo":"man@man.com","Posicion":"User","Token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6Im1hbiIsIm5iZiI6MTU0MjgzODU5OCwiZXhwIjoxNTQyODQwMzk4LCJpYXQiOjE1NDI4Mzg1OTgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjUyMjQiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjY1MjI0In0.W9Tck4QjzCoP2g0CdFIsmshSUoZbzi8AmzR9EnRYIVQ","Estatus":0}
最佳答案
在访问包含 JSON 的字符串中的实际数据之前,您必须先对其进行解析。使用 JSON.parse()
为此。
fs.readFile('user.json', function (err, data) {
if (err) throw err;
data = JSON.parse(data); // Convert JSON into an actual JavaScript object
console.log(data.Identificador); // Access object properties with the dot `.` notation
});
关于javascript - 我想从我的 json 文件中获取一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53422781/