javascript - Getting data from nested JSON object using angular GET -
i'm trying url nested json object, having trouble getting data. i'm not sure how data out of json object that's nested deeply.
app.controller('mainctrl', function($scope, $http) { $http.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3d'www.whitehouse.gov%2ffacts%2fjson%2fall%2fcollege%2520affordability'&format=json&diagnostics=true").then(function(responce) { $scope.status = responce; $scope.sortdata = responce.data.query.results.json.json.url; console.log(responce); console.log($scope.sortdata); }); });
i can console log object, don't know how url nested object. here's jsfiddle object console logged. help.
updated fiddle: https://jsfiddle.net/39pwve2x/23/
in data, url part of repeating array object (the last "json" node). url property of each "json" in array. if need of url's, pass array view , ng-repeat on it:
<body ng-app="javascripttest"> <div ng-controller="mainctrl"> <div ng-repeat="item in sortdata"> {{item.url}} </div> </div> </body>
...and controller...
var app = angular.module('javascripttest', []); app.controller('mainctrl', function($scope, $http) { $http.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3d'www.whitehouse.gov%2ffacts%2fjson%2fall%2fcollege%2520affordability'&format=json&diagnostics=true").then(function(responce) { $scope.sortdata = responce.data.query.results.json.json; }); });
you single url specifying index. example, if cared first url returned data, do:
$scope.firsturl = responce.data.query.results.json.json[0].url;
Comments
Post a Comment