我正在尝试通过引用解析JSON。我试着做这些例子,但没有输出信息。 get-query的结果是一个未解析的字符串。我如何获得信息?
截图:
<html ng-app="expeditionApp">
<head>
<meta charset="utf-8">
<title>Expedition</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script>
var expeditionApp = angular.module('expeditionApp', []);
expeditionApp.controller('expeditionCtrl', function ($scope, $http)
{
$http.get('http://localhost:3030/expedition/query?query=PREFIX exp: <http://sparql.sstu.ru:3030/expedition/> SELECT ?About ?RecDate ?LinkToVideo ?Duration WHERE {?video exp:hasVideoAbout ?About. ?video exp:hasRecDate ?RecDate. ?video exp:hasLinkToVideo ?LinkToVideo. ?video exp:hasDuration ?Duration.}')
.success(function(response) {
$scope.var = response;
console.log(response)
})
.error(function(response) {
alert(response);
console.log('Error: ' + response);
});
});
</script>
</head>
<body ng-controller="expeditionCtrl">
<h2>Example</h2>
<pre>{{var}}</pre>
<table class="table table-striped">
<tr>
<th>About</th>
<th>RecDate</th>
<th>LinkToVideo</th>
<th>Duration</th>
</tr>
<tr ng-repeat="item in var.data | orderBy: 'subject' ">
<td>{{item.About}}</td>
<td>{{item.RecDate}}</td>
<td>{{item.LinkToVideo}}</td>
<td>{{item.Duration}}</td>
</tr>
</table>
</body>
答案 0 :(得分:1)
您不能使用$ scope.var,var是关键字因此无法使用,请更改变量名称并重试。
使用$ scope.allData = response;
如果响应正是您所分享的内容(屏幕截图),则行应为:
$ scope.allData = response.data.results.bindings;