Reputation: 1180
l am working on ionic 4 project. l am try to get data json array from url using native http for ionic . When l try to get data array from url json l got empty page ! .
data json l have is too long , l put here short json to show scheme
{
"result": {
"airprotname": {
"code": "BGW"
},
"response": {
"airport": {
"plugin: {
"schedule": {
"arrival": {
"data": [
{
"flight": {
"identification": {
"id": iaw445,
"row": 4861006050
}
}
}
]
}
}
}
}
}
}
}
my code
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>
Upvotes: 1
Views: 651
Reputation: 73377
parse the intial response you get, before trying to access your nested data, so do...
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;
})
Upvotes: 1