为什么 AngularJS "$http.get().then(...)" 对纯文本文件有效,但对 JSON 文件无效?

Why does AngularJS "$http.get().then(...)" work on plain text files, but not JSON files?

这里有两个使用AngularJS "$http.get().then(...)" 的例子。一个读取纯文本文件,另一个读取 JSON 个文件。

read plain text vs read JSON

但是,第一个有效,第二个无效。除了 file1.txt、file2.txt、file3.txt 和 app.js 的第 23 行之外,其他一切都是一样的。

  /* content of file: 100 */

  function getNumber(file) {
      return $http.get(file).then(function(response){
         return parseInt(response.data, 10);
      });
  }

  /* content of file: [{'n':100}] */

  function getNumber(file) {
      return $http.get(file).then(function(response){
         return response[0].n;
      });
  }

我按照 this post 尝试创建服务,但仍然遇到一些错误。

基本上,如何使第二个工作?提前致谢!如果你看一下演示会更明确。

[{'n':100}] 无效 JSON。将其更改为 [{"n":100}]