Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

this is my code and need to retrieve some parts of json data

this my json data,in this i need to retrieve topology-id,node-id,tp-id which is in nested json array so write some code just check that once, and i am very new to angularjs.so help me out with this issue

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-base64/2.0.5/angular-base64.js"></script>
<body>
<div ng-app="list">
<div ng-controller="ListCtrl">
<ul ng-repeat="data in network-topology">
        <li >{{data.topology}}</li>

    </ul>
</div>
<div ng-controller="ListCtrl">
<ul ng-repeat="data1 in topology">
        <li >{{data1.topology-id}}</li>
</ul>
</div>
<div ng-controller="ListCtrl">
<ul ng-repeat="data2 in node">
        <li >{{data2.node-id}}</li>

    </ul>
</div>

<div ng-controller="ListCtrl">
<ul ng-repeat="data3 in termination-point">
        <li >{{data3.tp-id}}</li>  
    </ul>
</div>
<script>
var app = angular.module('list', ['base64']);
app.controller('ListCtrl', function($scope, $http, $base64) {

$http.defaults.headers.common = {"Access-Control-Request-Headers": "accept, origin, authorization"}; 
$http.defaults.headers.common['Authorization'] = 'Basic ' + $base64.encode('admin' + ':' + 'admin');

  $http({
    method: 'GET',
    url: 'http://10.132.32.212:8181/restconf/operational/network-topology:network-topology/',
    contentType: 'application/json; charset=utf-8',
  }).success(function(tdata) {
	$scope.network-topology= tdata.network-topology;
	$scope.topology= tdata.topology;
	$scope.topology-id = tdata.topology-id;
    $scope.node-id = tdata.node-id;
	$scope.tp-id = tdata.tp-id;
    $scope.topology= [];
    $scope.node= [];
    $scope.termination-point= [];
    angular.forEach(tdata.network-topology, function(network-topology, index){
               angular.forEach(network-topology.topology, function(topology, index){
    		     angular.forEach(network-topology.topology.node, function(node, index) {
                   angular.forEach(network-topology.topology.node.termination-point, function(termination-point, index){
                                                 $scope.termination-point.push(termination-point);
             });
    	 });
      });
  });

</script>
</body>
</html>

share|improve this question
1  
Please post your json data tdata – Nishant123 7 hours ago
    
{ "network-topology":{ "topology":[{"topology-id":"flow:1", "node":[ { "node-id":"openflow:1", "termination-point":[ {"tp-id":"openflow:1:2", "opendaylight-topology-inventory:inventory-node-connector-re‌​f":"/opendaylight-in‌​ventory:nodes – pramanaga koushik 7 hours ago

I think this will be your final code

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-base64/2.0.5/angular-base64.js"></script>
    <body>
    <div ng-app="list">
    <div ng-controller="ListCtrl">
    <div ng-repeat='data1 in data["network-topology"].topology'>
          {{data1["topology-id"]}}
            <div ng-repeat='data2 in data1.node'>
              {{data2["node-id"]}}

            <div ng-repeat='data3 in data2["termination-point"]'>
              {{data3["tp-id"]}}
            </div>
            </div>
        </div>
    </div>
</div>
    <script>
var app = angular.module('list', ['base64']);
app.controller('ListCtrl', function($scope, $http, $base64) {

   $http.defaults.headers.common = {"Access-Control-Request-Headers": "accept, origin, authorization"}; 
   $http.defaults.headers.common['Authorization'] = 'Basic ' + $base64.encode('admin' + ':' + 'admin');

 $http({
   method: 'GET',
   url: 'http://10.132.32.212:8181/restconf/operational/network-topology:network-topology/',
   contentType: 'application/json; charset=utf-8',
 }).success(function(tdata) {
   $scope.data= tdata;
  
      });
     });
 

</script>
</body>
</html>

share|improve this answer
    
but i am not getting anything , the empty browser is displaying – pramanaga koushik 5 hours ago
    
did you get any response in the $scope.data – Harish98 5 hours ago
    
i am getting the data – pramanaga koushik 5 hours ago
    
copy the data here – Harish98 5 hours ago
    
its very huge data – pramanaga koushik 5 hours ago

is this the complete code, once check this and let me know

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="list">
<div ng-controller="ListCtrl">
<div ng-repeat='data1 in data["network-topology"].topology'>
          {{data1["topology-id"]}}
            <div ng-repeat='data2 in data1.node'>
              {{data2["node-id"]}}

            <div ng-repeat='data3 in data2["termination-point"]'>
              {{data3["tp-id"]}}
            </div>
            </div>
        </div>
<script>
angular.module('list', []).controller('ListCtrl', function($rootScope) {
  $rootScope.jsonData={
"network-topology": {
  "topology": [{
    "topology-id": "flow:1",
    "node": [{
      "node-id": "openflow:1",
      "termination-point": [{
        "tp-id": "openflow:1:2",
        "opendaylight-topology-inventory:inventory-node-connector-re‌​f": "/opendaylight-in‌​ventory:nodes"
      }]
    }]
  }]
}
}
});
</script>
</body>
</html>

share|improve this answer

when you are using "-" in attributes to become subtraction in angularjs so,suggest to user underscore(network-topology instead of network_topology)

$rootScope.jsonData={
"network-topology": {
  "topology": [{
    "topology-id": "flow:1",
    "node": [{
      "node-id": "openflow:1",
      "termination-point": [{
        "tp-id": "openflow:1:2",
        "opendaylight-topology-inventory:inventory-node-connector-re‌​f": "/opendaylight-in‌​ventory:nodes"
      }]
    }]
  }]
}
}

view

<div ng-repeat='data1 in data["network-topology"].topology'>
          {{data1["topology-id"]}}
            <div ng-repeat='data2 in data1.node'>
              {{data2["node-id"]}}

            <div ng-repeat='data3 in data2["termination-point"]'>
              {{data3["tp-id"]}}
            </div>
            </div>
        </div>

output:

flow:1
openflow:1
openflow:1:2
share|improve this answer
    
but the json data i have to get from the url, and the json data can be increased time to time because it is a network configuration – pramanaga koushik 6 hours ago
    
and can u send me the entire code – pramanaga koushik 6 hours ago
    
just copied your response in a variable and worked on it to show output. – Harish98 6 hours ago
    
i am new to angularjs can u send me the code – pramanaga koushik 6 hours ago
    
if this works for you vote for the answer – Harish98 5 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.