如何从AngularJs中的rest api获取这个json数据?

时间:2015-04-27 18:28:39

标签: json angularjs restful-url ngresource

{
    "id": "Countries",
    "body": [
        {
            "id": "0629ef6a6d4cf612265ccd47f23e575a",
            "countryCode": "USA",
            "currency": "USD"
        },
        {
            "id": "0a1892ad5c6e0cc51fe981dfbe76a983",
            "countryCode": "EUROPE",
            "currency": "EUR"
        },
        {
            "id": "0a1892ad5c6e0cc51fe981dfbeac4778",
            "countryCode": "JAPAN",
            "currency": "JPY"
        },
        {
            "id": "864d47ed14f1ac86152b9729e1e43515",
            "countryCode": "IND",
            "currency": "INR"
        }
    ]
}

我如何获得$scope.body.countryCode;

假设一个rest api正在提供这个json(而不是jsonp)那么我如何使用angular js读取它?

1 个答案:

答案 0 :(得分:1)

基于有限的评论:



$http({
  url: 'countries.json',
  method: 'GET'
  }).success(function(data) {
     $scope.countries = data;
  )}.error(function(data) {
     console.log("error occurred."); 
   })