如何使用Angular从多行json对象获取数据

如何使用Angular从多行json对象获取数据,json,angularjs,http,Json,Angularjs,Http,$HTTPGET请求资源api返回多行json后:(示例) 如何从这些数据中获取id $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

$HTTPGET请求资源api返回多行json后:(示例)

如何从这些数据中获取id

$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');
  });
我用的方法不正确,有什么建议吗?
提前谢谢你

您的
JSON
无效,您需要如下更改,然后重试

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

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

注意:
features
array包含object,所以需要用
{}

将其括起来。这个json似乎无效,features是一个数组,并且包含键值。如果您想在json中测试、使用和粘贴,那么它应该是一个目标;它将为您验证它。thanx,如果它是功能中的多个对象,我应该首先迭代它以将结果放入数组中吗?是的<代码>{“功能”:[{“id”:“001”},{“id”:“002”}]}
var data = {
    "features": [{
        "type": "feature",
        "properties": {
            "id": "001",
            "name": "Example"
        }
    }]
};

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