0
在这里,我想从json数据中检索一些场景。 这是我的JSON数据:如何使用angularjs访问json数组中的一个particuar字段
[{"ipaddress":"10.132.32.212","id":"18"},
{"ipaddress":"10.132.32.213","id":"19"}]
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
\t <div ng-app="lostsysApp" ng-controller="mainController">
\t <ul>
<li ng-repeat="x in ipaddress | orderBy:'id'">
{{ x.ipaddress + ', ' + x.id }}
</li>
</ul>
</div>
<script>
var app = angular.module('lostsysApp', []);
app.controller('mainController', function($scope, $http) {
$http({ method : "GET",
url : "http://10.132.32.218:8080/DBtoWeb/services.jsp",
Accept: "application/json"
}).then(function mySucces(response) {
$scope.myData=response.data;
}, function myError(response) {
//Second function handles error
$scope.myData = "Something went wrong";
});
});
</script>
</body>
</html>
多数民众赞成也没有在上面的JSON数据,我需要ip地址和id –
,并且假定response.data确实包含你说它的数据(JSON数组),那么上述代码将起作用。 –
没错的价值观工作 –