使用 angular 将对象写入 .json 文件?

Use*_*101 1 angularjs

我有一个对象,如:

    [
        {
          "text" : "Address of Bowlers game center in Chennai?",
          "entities" : [
            {
              "entity" : "action",
              "value" : "business"
            },
            {
              "entity" : "intent",
              "value" : "fetchItems"
            },
            {
              "entity" : "bizCategory",
              "value" : "bowling",
              "start" : 11,
              "end" : 30
            },
            {
              "entity" : "wit$location",
              "value" : "Chennai",
              "start" : 34,
              "end" : 40
            }
          ]
        },
        {
          .....more objects
        }
]
Run Code Online (Sandbox Code Playgroud)

现在我必须对这个对象进行一些操作,并.json使用 angular js将操作的对象保存到一个文件中。

var originalObject = $http.get("data/chennai.json");
var manipuatedObject;  // this is the manipulated object i get after applying some changes on originatalObject.
Run Code Online (Sandbox Code Playgroud)

现在如何将其保存manipuatedObject到 json 文件中。

小智 8

尝试这个:

function saveText(text, filename){
  var a = document.createElement('a');
  a.setAttribute('href', 'data:text/plain;charset=utf-u,'+encodeURIComponent(text));
  a.setAttribute('download', filename);
  a.click()
}
Run Code Online (Sandbox Code Playgroud)

所以一个可能的用途可能是:

var obj = {a: "Hello", b: "World");
saveText( JSON.stringify(obj), "filename.json" );
Run Code Online (Sandbox Code Playgroud)