js/jsfun/fnJson.js json文件操作
let jsonFile = fnJsa_jsCodePath() + "/demoresource/test.json"
let data={"title":"标题","info":{"title":"商品","price":123.42,"tag":"aa"},"ts":fnTime_timestamp()};
fnIO_saveFile(jsonFile,JSON.stringify(data),true)
data = fnJson_config(jsonFile)
console.log("json数据:",data)
fnJson_configUpdate(jsonFile,"info.price",100)
fnJson_configUpdate(jsonFile,"info.addtime",fnTime_timestamp())
fnJson_configDelete(jsonFile,"info.tag")
data = fnJson_config(jsonFile)
console.log("json数据:",data)
//JSON 列表操作
let jsonListFile=fnJsa_jsCodePath()+"/demoresource/json/list.json"
fnIO_createFolder(jsonListFile)
let listData=[{"id":1,"title":"标题1"},{"id":2,"title":"标题2"},{"id":3,"title":"标题3"}]
fnIO_saveFile(jsonListFile,JSON.stringify(listData),true)
console.log("info(id=2):", fnJson_listInfo(jsonListFile,{"id":2}));
for (let i = 4; i < 20; i++) {
fnJson_listInsert(jsonListFile,{"id":i,"title":"标题"+i})
}
console.log("list数据,新增:", fnJson_list(jsonListFile));
fnJson_listUpdate(jsonListFile,{"title":"标题3333"},{"id":3})
console.log("list数据,更新:", fnJson_list(jsonListFile));
fnJson_listDelete(jsonListFile,{"id":1})
console.log("list数据,删除:", fnJson_list(jsonListFile));
console.log("list分页1:", fnJson_listPage(jsonListFile,"id"))
console.log("list分页2:", fnJson_listPage(jsonListFile,"id",{},"",2))
console.log("list分页3:", fnJson_listPage(jsonListFile,"id",{},"",3))