在AngularJS中解析Json数组

在AngularJS中解析Json数组,angularjs,json,Angularjs,Json,我是angularjs的新手。如何使用angularjs在html中显示json。下面是代码 var app = angular.module('myapp', []); app.controller('myctrl', function($scope, $http) { $http.get("http://localhost:8080/xyz").then(function (response) { }); }); Reponse is : [ { "city

我是angularjs的新手。如何使用angularjs在html中显示json。下面是代码

var app = angular.module('myapp', []);
app.controller('myctrl', function($scope, $http) {
    $http.get("http://localhost:8080/xyz").then(function (response) {

    });
});

Reponse is :

[
  {
    "city": "animal"
  },
  {
    "city": "bird"
  }
]

在控制器中,应将json分配给一个作用域:

app.controller('myctrl', function($scope, $http) {
    $scope.myArray = [];
    $http.get("http://localhost:8080/xyz").then(function (response) {
        $scope.myArray = response;
    });
});
然后在您看来,您可以执行以下操作:

<div ng-controller="myctrl">
    <ul ng-repeat="obj in myArray">
        <li>{{obj.city}}</li>
    </ul>
</div>

  • {{obj.city}

像这样使用
ng repeat

<div ng-repeat="t in test">
  <span>{{t.city}}</span>
</div>

{{t.city}

使用以下代码这可能会对您有所帮助

myArray = JSON.parse(response);

for ( var index in myArray ) {

var singleObject = myArray[index];
var keys = Object.keys[singleObject];
      for ( var j in keys ) {
            console.log("Value of key"+j+"is"+keys[j]+"in Object"+index);
      }
}
这里的响应是一个字符串值。

试试这个 那里的记录是这样的

{"records":[{"ID":"235","user_id":"2","project_id":"186","project_cid":"2900669120142632939","imagePath":"media/pano/sv_02a29.jpg","ImageName":"1.jpg"},{"ID":"236","user_id":"2","project_id":"186","project_cid":"2900669120142632939","imagePath":"media/pano/sv_f0f59.jpg","ImageName":"253.jpg"},{"ID":"239","user_id":"2","project_id":"186","project_cid":"1997319193267363957","imagePath":"media/pano/sv_6536f.jpg","ImageName":"PANOCLOUD_meta.jpg"},{"ID":"240","user_id":"2","project_id":"186","project_cid":"6736594884768838469","imagePath":"media/pano/sv_898ca.jpg","ImageName":"Boscolo Hotel Budapest.jpg"}]}



$http.get("moderatorData.php").then(function (response) {
                $scope.panoramas = response.data.records;
            });
然后像这样打印

<li class="align" ng-repeat="pano in panoramas>
<img ng-src="{{pano.imagePath}}"  style="height: 90px;" />
</li>

在Plunker中显示,但在我的页面中没有显示。我检查了两次JSON链接,它给出了响应。但是数据没有显示