Angular的$http请求中用于到达JSON的proprer子级的点表示法不起作用



我是AngularJS的新手。我将一个命令POST到服务器,服务器会给我回复。我的POST命令工作正常,因为我把响应放在警报视图中,它以JSON的形式返回,所以我可以在警报视图内看到响应。

这是我的代码:

var appControllers = angular.module('app', ['jsonService']);
appControllers.controller('post', function($scope, $http) {
            $http({
                withCredentials: true,
                method : 'POST',
                url : 'http://myURL/command',
                data : 'myData',
                headers : {
                'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8'
                }
                }).success(function (data, status, headers, config) {
                        var JSONData = JSON.stringify(data);
                        $scope.persons = JSONData;
                           alert(JSONData);// assign  $scope.persons here as promise is resolved here
                }).error(function (data, status, headers, config) {
                        $scope.status = status;
                         alert(status);
                });
    });

我的问题:我想解析JSON中的一个特定项。我知道我应该使用点符号来到达JSON的适当子级,但如果我使用点符号,它就不起作用了。

这是我的HTML代码:

<ul data-ng-controller="post">
        <li ng-repeat="person in persons">
        <div><a href="http://button2" data-role="button" ng-bind="person.firstName"></a></div>
        </li>
    </ul>

任何提示或帮助都将不胜感激。

删除:

  var JSONData = JSON.stringify(data);

只需使用"数据"。您正在将javascript对象转换回字符串。您希望将其用作对象。

  $scope.persons = data;

最新更新