I am currently working on parsing a nested JSON using AngularJS. Here is an example of the nested JSON structure:
{
"results": [
{
"id": "D1",
"name": "A",
},
{
"id": "D2",
"name": "B",
}
]
}
Below is the AngularJS controller that retrieves the JSON data from PHP, but is currently returning [object object] instead of the expected JSON data. Furthermore, when attempting to access the JSON data, it returns an 'undefined' value.
function MyController($scope, $http) {
$http({
method: 'GET',
data: "action=0",
url: 'a.php'
}).then(function(data) {
alert("Hello" +data); //alerts Hello[object Object]
$scope.legs = data.results;
alert($scope.legs); //alerts undefined
});
}
Here is the HTML code snippet that attempts to display the JSON data:
<tr ng-repeat="l in legs">
<td>{{ l.id }}</td>
</tr>