gpt4 book ai didi

angular - ionic 4 native http 获取空数组

转载 作者:可可西里 更新时间:2023-11-01 17:17:38 25 4
gpt4 key购买 nike

我正在从事 ionic 4 项目。我正在尝试使用 ionic 的 native 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>

doc for native http

最佳答案

在尝试访问您的嵌套数据之前解析您得到的初始响应,所以...

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;
})

关于angular - ionic 4 native http 获取空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54540802/

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