如何在Angular 2中读取JSON文本
抱歉,但是我无法阅读Angular 2&4中非常具体的JSON值,在这里我可以获取并显示列表的名称,但是!但是我找不到一种方式在页面中显示,比如在JSON文档中,我是这样说的:从中获取,我使用邮递员检查所有内容,我可以获取相册的名称和其他内容,但是获取文本来使用图像,这很奇怪如何在Angular 2中读取JSON文本,json,angular,angular2-forms,Json,Angular,Angular2 Forms,抱歉,但是我无法阅读Angular 2&4中非常具体的JSON值,在这里我可以获取并显示列表的名称,但是!但是我找不到一种方式在页面中显示,比如在JSON文档中,我是这样说的:从中获取,我使用邮递员检查所有内容,我可以获取相册的名称和其他内容,但是获取文本来使用图像,这很奇怪 "topalbums": { "album": [ { "name": "The Very Best of Cher", "playcount": 1663904,
"topalbums": {
"album": [
{
"name": "The Very Best of Cher",
"playcount": 1663904,
"mbid": "a7e2dad7-e733-4bee-9db1-b31e3183eaf5",
"url": "https://www.last.fm/music/Cher/The+Very+Best+of+Cher",
"artist": {
"name": "Cher",
"mbid": "bfcc6d75-a6a5-4bc6-8282-47aec8531818",
"url": "https://www.last.fm/music/Cher"
},
**// +++++++++++++++++++THIS PART +++++++++++++++++++++!!!!!**
"image": [
{
// I'M TRYING TO USE THIS INFORMATION
"#text": "https://lastfm-img2.akamaized.net/i/u/34s/287bc1657795451399d8fadf64555e91.png",
"size": "small"
},
{
"#text": "https://lastfm-img2.akamaized.net/i/u/64s/287bc1657795451399d8fadf64555e91.png",
"size": "medium"
},
{
"#text": "https://lastfm-img2.akamaized.net/i/u/174s/287bc1657795451399d8fadf64555e91.png",
"size": "large"
},
{
"#text": "https://lastfm-img2.akamaized.net/i/u/300x300/287bc1657795451399d8fadf64555e91.png",
"size": "extralarge"
}
]
},
我想要的是获取图像的url,我尝试通过以下方式获取:
src="{{list.image[0]['#text']}}"
artist.component.html
首先,如果要获取图像数组的第一个位置,应该访问位置0而不是1。。。此外,您没有文本,但有文本: 要解决您的问题,您可以这样做:
src="{{list.image[0]['#text']}}"
或者更好:
你试过src={{list.image[0]['text']}或者更好的[src]=list.image[0]['text']}吗?天哪,谢谢!!!!!!!!!!
src="{{list.image[0]['#text']}}"
[src]="list.image[0]['#text']"