Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建JSON-5_Json_Angular_Angular5 - Fatal编程技术网

创建JSON-5

创建JSON-5,json,angular,angular5,Json,Angular,Angular5,我有一个JSON读到用户界面和修改文件作为审查过程的一部分。最后,我想将新数据保存到新文件夹/文件中。 下面的代码示例-始终以错误后调用结束: SaveFinalData(){ this.postJson<Reaction> ('./assets/ICP/Reviewed/Json/out.json', this.reactionDatabase.reactiondataChange.value); } postJson<Reaction>(url:

我有一个JSON读到用户界面和修改文件作为审查过程的一部分。最后,我想将新数据保存到新文件夹/文件中。 下面的代码示例-始终以错误后调用结束:

SaveFinalData(){

 this.postJson<Reaction> 
 ('./assets/ICP/Reviewed/Json/out.json',
    this.reactionDatabase.reactiondataChange.value);
 }

postJson<Reaction>(url: string, Reaction: any){

//let body = JSON.stringify({ Reaction });   

this.http.post(url, body)
.subscribe(
    (val) => {
        console.log("POST call successful value returned in body", val);
    },
    response => {
      console.log("POST call in error", response);
    },
    () => {
        console.log("The POST observable is now completed.");
    });
结果——没有运气

(二)

})

结果——没有运气-->给出错误fs。writeFile不是函数


请帮助/指导我获得最终结果…谢谢

您打算从服务器还是从前端下载文件?不…我正在尝试将输出文件写入服务器上的特定路径…您是否使用Angular在服务器上写入文件?使用Angular 5抱歉,您需要使用一些后端技术(如Node.js)在服务器上编写文件。Angular是一种前端技术,不适合您的要求。
var theJSONdata = JSON.stringify({ Reaction }); 
   window.localStorage.setItem('./assets/ICP/Reviewed/Json/out.json', theJSONdata)
var jsonfile = require('jsonfile') 
var file = './assets/ICP/Reviewed/Json/out.json'
var obj = {name: 'JP'} //SAMPLE DATA

jsonfile.writeFile(file, obj, function (err) {
console.error(err)