I've tried searching through StackOverflow regarding this issue but could not find a solution that worked for me. I'm using AngularJS. I have simple controller that calls a http service and reads the response data. In this specific case, I have a JSON output with an objects array I am unable to read.
Here's the JSON output:
{
"results": [{
"id": "1",
"download_url": "",
"uploader": {
"id": "114899"
},
"uploaded": "1442599380",
"streaming_url_timeout": 1446092554
}, {
"id": "2",
"download_url": "",
"uploader": {
"id": "114899"
},
"uploaded": "1442599380",
"streaming_url_timeout": 1446092554
}]
}
I'm trying to get access to items in 'results'. This is my Service that retrieves the JSON data:
this.getUData = function() {
var deferred = $q.defer();
$http.jsonp(API_URL + 'udata')
.success(function(data) {
deferred.resolve(data);
})
.error(function(data) {
deferred.reject(data);
});
return deferred.promise;
}
And then this is how i call this service from my controller:
myservices.getUData().then(function(data) {
$scope.uitems = data.results;
});
Template:
<div class="item" href="#" ng-repeat="item in uitems">
<h2>{{item.id}}</h2>
</div>
But when I try to access the items in 'results', I get the following error:
Uncaught SyntaxError: Unexpected token :
The line in question for this error is "results":[