意外标记{解析';有效';json时

意外标记{解析';有效';json时,json,angularjs,Json,Angularjs,当我按下按钮时,我试图将存储在json中的数组分配到控制器中的数组中。我在几个在线验证器上运行了我的json,所有这些验证器都声称我的json有效。但是,当我去解析它时,我得到了一个意外的令牌错误 我已经仔细检查了所有内容,我认为所有内容都与我正在学习的教程非常接近,但它只是不想起作用 相关控制器线路: angular.module('myApp.controllers', []) .controller('PlayerAdditionCtrl', function($scope, $htt

当我按下按钮时,我试图将存储在json中的数组分配到控制器中的数组中。我在几个在线验证器上运行了我的json,所有这些验证器都声称我的json有效。但是,当我去解析它时,我得到了一个意外的令牌错误

我已经仔细检查了所有内容,我认为所有内容都与我正在学习的教程非常接近,但它只是不想起作用

相关控制器线路:

angular.module('myApp.controllers', [])
  .controller('PlayerAdditionCtrl', function($scope, $http) {
        $scope.players = [];
        $scope.loadDefaults = function()
        {
            $http.get('defaults.json').success(function(array)
            {
                        //assignment here
            });
        }
  });
完整的json:

[
    { 
        "name": "Mike",
        "color": "teal"
    },
    {
        "name": "Madre",
        "color": "seagreen"
    },
    {
        "name": "Anthony",
        "color": "royalblue"
    },
    {
        "name": "GI-Joe",
        "color": "olivedrab"
    }
]
来自chrome的完整错误文本:

    SyntaxError: Unexpected token {
        at Object.parse (native)
        at fromJson (http://localhost:8000/app/bower_components/angular/angular.js:1078:14)
        at $HttpProvider.defaults.defaults.transformResponse (http://localhost:8000/app/bower_components/angular/angular.js:7317:18)
        at http://localhost:8000/app/bower_components/angular/angular.js:7292:12
        at Array.forEach (native)
        at forEach (http://localhost:8000/app/bower_components/angular/angular.js:323:11)
        at transformData (http://localhost:8000/app/bower_components/angular/angular.js:7291:3)
        at transformResponse (http://localhost:8000/app/bower_components/angular/angular.js:7963:17)
        at wrappedCallback (http://localhost:8000/app/bower_components/angular/angular.js:11319:81)
        at http://localhost:8000/app/bower_components/angular/angular.js:11405:26 angular.js:9778
    (anonymous function) angular.js:9778
    (anonymous function) angular.js:7216
    wrappedCallback angular.js:11322
    (anonymous function) angular.js:11405
    Scope.$eval angular.js:12412
    Scope.$digest angular.js:12224
    Scope.$apply angular.js:12516
    done angular.js:8204
    completeRequest angular.js:8412
    xhr.onreadystatechange angular.js:8351

再次检查您的json/和/或/pathtojson您的代码对我有效


我重新启动并再次尝试(在没有更改任何内容后),它成功了。我不太清楚为什么。