search

Home  >  Q&A  >  body text

angular.js - How to read a field in json with angularjs?

The data is saved in a json file. I want the data of the id segment in the json data. How can I get it and convert it into string type?

json:

[{
"id": "AD01",
"imgurl": "images/banner_01.jpg",
  "bannerurl": [
    {"bannerimgurl": "images/banner_04.jpg"},
    {"bannerimgurl": "images/banner_05.jpg"}],
"status": "0"
},
{
"id": "AD02",
"imgurl": "images/banner_02.jpg",
  "bannerurl": [
    {"bannerimgurl": "images/banner_04.jpg"},
    {"bannerimgurl": "images/banner_03.jpg"}],
"status": "0"
}]

js:

$http.get("json/test.json").success(function(response){$scope.datas = response;
alert(JSON.stringify($scope.datas));//这样获取到的只是整个json的内容。
//alert(JSON.stringify($scope.datas.id));这样返回的值是undefined。
}).error(function(){})
PHPzPHPz2831 days ago1248

reply all(6)I'll reply

  • PHPz

    PHPz2017-05-15 16:53:22

    Let’s traverse this json object

    var array = [];
    for(var item in response){
      array.push(JSON.stringify(item.id));
    }
    $scope.array = array;
    

    reply
    0
  • 迷茫

    迷茫2017-05-15 16:53:22

    .....

    $scope.datas[0].id
    

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-15 16:53:22

    I usually match loadsh#result

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-15 16:53:22

    May I ask if your problem has been solved? I also encountered this problem

    reply
    0
  • ringa_lee

    ringa_lee2017-05-15 16:53:22

    $scope.datas = angular.fromJson($scope.datas);
    alert(JSON.stringify($scope.datas.id));

    You try this

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 16:53:22

    Has the original poster solved it?

    reply
    0
  • Cancelreply