2017-06-05 79 views
-1

我想通過引用來解析JSON。我試圖做的例子,但信息不輸出。 get-query的結果是一個未解析的字符串。我如何獲得信息?Angular Json解析。我究竟做錯了什麼?

截圖:

window

JSON

<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> 

+2

請將您的JSON顯示爲實際文字,而不是圖片文字。你的「窗口」截圖也沒有意義。這應該表明什麼?最後,我很驚訝這個URL甚至考慮了它是多麼畸形。 –

回答

1

不能使用$ scope.var,VAR因此不能使用,改變變量名,並嘗試關鍵字再次。

使用$ scope.allData = response;

如果響應是您分享什麼(截圖),那麼行應該是:

$ scope.allData = response.data.results.bindings;