gpt4 book ai didi

javascript - 访问 JSON 数据 - 未定义

转载 作者:行者123 更新时间:2023-12-03 05:43:03 25 4
gpt4 key购买 nike

我有这个 json:

{
"total": 1,
"per_page": "10",
"current_page": 1,
"last_page": 1,
"next_page_url": null,
"prev_page_url": null,
"from": 1,
"to": 1,
"data": [
{
"id": 2,
"name": "Artista di prova",
"artist_hash": "Gqrrx6NrtqqMpvEN",
"spotify_followers": null,
"spotify_popularity": 66,
"image_small": null,
"image_large": null,
"fully_scraped": 0,
"updated_at": "2016-11-06 08:21:02",
"bio": "",
"wiki_image_large": null,
"wiki_image_small": null,
"tracks": [
{
"id": 1,
"name": "Traccia di prova",
"album_name": "Album di prova",
"number": 1,
"duration": 18133,
"artists": [
"Artista di prova"
],
"youtube_id": null,
"spotify_popularity": 50,
"album_id": 1,
"temp_id": null,
"url": "http://myapp.app/track/1/mov/stream",
"artist_id": 2
},
{
"id": 3,
"name": "Traccia di prova 2",
"album_name": "Album di prova",
"number": 1,
"duration": 18133,
"artists": [
"Artista di prova"
],
"youtube_id": null,
"spotify_popularity": 50,
"album_id": 1,
"temp_id": null,
"url": "http://myapp.app/track/1/mov/stream",
"artist_id": 2
}
]
}
]

}

我需要访问 tracks 字段并获取所有数据。
我尝试过:

$http.get('artist', {params:params}).success(function(response) {
$scope.items = response.data;
$scope.tracks = response.data.tracks;

console.log($scope.tracks);


})
};

但我得到未定义

如何访问tracks字段?

最佳答案

响应的

data 属性是一个数组,因此需要通过索引访问它:

response.data[0].tracks;

关于javascript - 访问 JSON 数据 - 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40447911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com