新建一个student,json{
“student”:["
{“name”:" wanglin“,
“age”:33
}
]
}
在建一个student.js文件
const fs=require(“fs”)
fs.readFile(“student.json”,(error,data)=>{
console.log(error)
)}
console.log(data)//先读取student.json,里面内容object内容
const hh=json.para(data)//必须转为json para(data)类型
hh.student.push({name:"李四“。age:33})//hh存储着student,转为parajson 类型。j就是我们需要添加类型(name:"李四“,age:33),没有转化之前为“{“name”:“李四”,“age”:33}
具体区别仔细看打印出来即懂
存进去则还是需要转换为json stringfy(_)类型,
const jj= JSON.stringfy(hh)
写入 fs.writeFile(“student.json”,jj(error)=>{
console.log(error)
)}