Json data not being displayed

why is that when my json data is with bracket is not being displayed


this below works just fine


here is my controller

.controller('TestController', function($scope, $http){
    console.log('Success', resp);
    $scope.name = resp.data.name;
    }, function (err){

i use {{name}} to display on html file the json data

I love JSON because it’s structure is actually almost identical (a little more strict) to Javascript objects!

Your first example has the [ ] around it, which means that it is an ARRAY type. So you have an array, and the index 0 of the array is your object with name and state.

The second example doesn’t have the [ ] which means that it just resembles an object with the properties name, and state.

So if you want to use it with the brackets, the line where you set your name is going to look more like this:

$scope.name = resp.data[0].name;

Hope that helps you out!