angular.js - How to read a field in json with angularjs?
PHPz
PHPz 2017-05-15 16:51:22
0
6
1195

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(){})
PHPz
PHPz

学习是最好的投资!

reply all(6)
PHPzhong

Let’s traverse this json object

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

.....

$scope.datas[0].id
大家讲道理

I usually match loadsh#result

漂亮男人

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

左手右手慢动作
$scope.datas = angular.fromJson($scope.datas);
alert(JSON.stringify($scope.datas.id));

You try this

Ty80

Has the original poster solved it?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template