【发布时间】:2021-03-03 13:40:58
【问题描述】:
如何从这个 json 中获取信息以 10 角绘制它们
{
"countries": [
{
"id": 1,
"name": "United States"
},
{
"id": 2,
"name": "India"
}
],
"states": [
{
"id": 1,
"countryId": 1,
"name": "Alabama"
},
{
"id": 2,
"countryId": 1,
"name": "Alaska"
}
]
}
对于普通的 json,我使用了这个,但是那个 jeson 有 2 个数组,它不会让我
return this.http.get<Country[]>("./assets/data.json");
尝试区分“[object Object]”时出错。只允许使用数组和可迭代对象
<!-- html -->
<div *ngFor="let item of countri">
{{item.id}}
</div>
型号
export interface Country {
id: number;
name: string;
}
和我的订阅
countri: Country[] = [];
this.countriesService.getCountries().subscribe(
countri => {
this.countri = countri;
console.log(countri);
},
err => console.log(err)
);
【问题讨论】:
-
任何答案对您有用吗?如果是,请考虑接受/支持他们。 What should I do when someone answers my question?
标签: arrays json angular dictionary object