This is a question I truly feel stupid for asking. But I have searched the web and haven't found a specific example with my problem. Luckily, the question is simple. I have the following JSON data being read in by AngularJS as follows:
return $http.post('getData.htm').then(function(response) {
console.log("response.data: " + response.data);
var roles = angular.fromJson(response.data).model.results;
return roles;
});
The console in this scenario outputs the following:
response.data: {"model":{"results":["1","2","3","4","5","6","7","8","9","10","11"],"totalCount":11}}
I expect roles
to contain an array with those numbers, however when I print out the value of roles
it simply says [object Object]
.
How do I access the numbers contained in the results
array?
thanks a lot!
JSON.stringify(response.data)
? – Maxim Shoustin Jul 3 '14 at 11:36response.data
is all you need. In adding theangular.fromJson
call, you're effectively creating another object, deserialized from the JSON response. – Ben Jul 3 '14 at 11:47