我想从我的json文件中带一个值

时间:2018-11-22 01:42:25

标签: javascript node.js json

这为我带来了json文件的所有值

示例:我有ID,姓名和姓氏,我想带ID值

run()

信息文件json

background-image: url($background_image); 
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
z-index: -1;

position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;

1 个答案:

答案 0 :(得分:1)

在访问包含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
});
相关问题