user3069270
user3069270

Reputation: 52

how to get data from multyline json object using Angular

After an $http get request resource api gives back a multyline json:(example)

{"features":["type": "feature", "properties":{ "id": "001", "name": "Example"}]}

How can i get an id from that data?

$scope.myDate = $http.get('http://example.com/').
  success(function(data, status){
    var test = data.features;
    $scope.information = test['type'];

  }).
  error(function(data, status){
    console.log('not');
  });

The way i used isn't correct, so any suggestions? Thank you, in advance!

Upvotes: 0

Views: 44

Answers (1)

Asik
Asik

Reputation: 7977

Your JSON is not valid, you need to change it as follows and then try

var data = {
    "features": [{
        "type": "feature",
        "properties": {
            "id": "001",
            "name": "Example"
        }
    }]
};

alert(data.features[0].type);

Note: features array contains object, so you need to enclose that with {}

Upvotes: 1

Related Questions