javascript - SyntaxError : Unexpected token o at Object. 解析( native )AngularJS

标签 javascript json angularjs angularjs-http

来自 AngularJS 菜鸟的问题。

我正在尝试使用 asmx 网络服务来显示网格。我测试了 Web 服务,它正确输出了 JSON 数据。 这是我的 Controller

app.controller('SetupController', ['$scope', '$http', function ($scope, $http) {

    var url = 'app/pricefilessetup/grid.asmx/getGridJson';

    $http.get(url).success(function (data) {
        var myjson = JSON.parse(data);
        $scope.products= JSON.parse(myjson);
    });
}]);

由于某种原因,SO 不允许我粘贴 html,但它基本上有一个 ng-controller 指令和 ng-repeat 来循环遍历 JSON 数据。

当我运行这个网络应用程序时,我得到了错误

SyntaxError: Unexpected token o 在 Object.parse ( native ) 它指向下一行

  $scope.questions = JSON.parse(myjson);

我尝试使用 alert 检查 myjson 的值,它显示 [object Object], [object Object], ...

这里有什么我遗漏的地方

最佳答案

我认为返回的数据已经是 JSON,不需要 JSON.parse(),除非它是字符串格式。

$scope.products= data;

关于javascript - SyntaxError : Unexpected token o at Object. 解析( native )AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29763557/

相关文章:

javascript - 将 AngularJS 与 innerHTML 一起使用

javascript - 在mongodb中插入数据时添加条件

javascript - JQuery - 图像悬停在另一个图像后面的事件

python - flask jsonify : object is not iterable

javascript - 将 ES6 箭头函数转换为 ES5 函数 JavaScript

javascript - angular-ui 和 datepicker 指令错误

javascript - 我们如何使用 Vue Js 为 Kendo UI 网格列上的自定义复选框绑定(bind)事件?

javascript - 自动完成组合框

javascript - 在 Angularjs 中更改 JSON 请求和响应中的字段/属性名称

json - 字段 'browser' 不包含 react 的有效别名配置