ionic 4 native http 获取空数组
ionic 4 native http get empty array
我正在处理 ionic 4 项目。我正在尝试使用 ionic 的本机 http 从 url 获取数据 json 数组。当我尝试从 url json 获取数据数组时,我得到了空页! .
数据json我太长了,我在这里放短json以显示方案
{
"result": {
"airprotname": {
"code": "BGW"
},
"response": {
"airport": {
"plugin: {
"schedule": {
"arrival": {
"data": [
{
"flight": {
"identification": {
"id": iaw445,
"row": 4861006050
}
}
}
]
}
}
}
}
}
}
}
我的代码
export class HomePage {
public items : any[] ;
constructor(private http: HTTP) {
this.http.get('/airport.json?code=BGW', {}, {})
.then(res=> {
this.items = JSON.parse(res.data.result.response.airport.plugin.schedule.arrival.data)
})
.catch(error => {
});
}
}
html
<ion-content>
{{status}}
<ion-list>
<ion-item *ngFor="let item of items">
{{item.flight.identification.id}}
<div class="item-note" slot="end">
</div>
</ion-item>
</ion-list>
</ion-content>
在尝试访问您的嵌套数据之前分析您得到的初始响应,所以...
this.http.get('/airport.json?code=BGW', {}, {})
.then(res=> {
const parsed = JSON.parse(res.data);
this.items = parsed.result.response.airport.plugin.schedule.arrival.data;
})
我正在处理 ionic 4 项目。我正在尝试使用 ionic 的本机 http 从 url 获取数据 json 数组。当我尝试从 url json 获取数据数组时,我得到了空页! .
数据json我太长了,我在这里放短json以显示方案
{
"result": {
"airprotname": {
"code": "BGW"
},
"response": {
"airport": {
"plugin: {
"schedule": {
"arrival": {
"data": [
{
"flight": {
"identification": {
"id": iaw445,
"row": 4861006050
}
}
}
]
}
}
}
}
}
}
}
我的代码
export class HomePage {
public items : any[] ;
constructor(private http: HTTP) {
this.http.get('/airport.json?code=BGW', {}, {})
.then(res=> {
this.items = JSON.parse(res.data.result.response.airport.plugin.schedule.arrival.data)
})
.catch(error => {
});
}
}
html
<ion-content>
{{status}}
<ion-list>
<ion-item *ngFor="let item of items">
{{item.flight.identification.id}}
<div class="item-note" slot="end">
</div>
</ion-item>
</ion-list>
</ion-content>
在尝试访问您的嵌套数据之前分析您得到的初始响应,所以...
this.http.get('/airport.json?code=BGW', {}, {})
.then(res=> {
const parsed = JSON.parse(res.data);
this.items = parsed.result.response.airport.plugin.schedule.arrival.data;
})