我有这样的json结果
{
"modelList":["modelName1","modelName2"],
"modelNamesList":["modelName1","modelName2"],
"yearList":["2021","2020","2019","2018"]
}
我只需要上面对象的年份列表,所以我不知道该怎么做,谁能帮助我,谢谢
我做过这样的事情
home.component.ts
export class HomeComponent implements OnInit {
catlogData: any ={
"modelList":["modelName1","modelName2"],
"modelNamesList":["modelName1","modelName2"],
"yearList":["2021","2020","2019","2018"]
};
ngOnInit(): void {}
home.component.html
<ul *ngFor="let a of catlogData">
<li>year:{{a.yearList[i]}}
</li>
</ul>
答案 0 :(得分:2)
您可以直接从 class main():
def __init__(self):
self.Width = int(input("Enter the Width:"))
self.Height = int(input("Enter the Height:"))
def area(self):
a = (self.Width * self.Height)
print("The area is", a)
def perimeter(self):
p = self.Width * 2 + self.Height * 2
print("The perimeter is", p)
# instantiate a "main" object called "rectangle"
rectangle = main()
# call the "area" method
rectangle.area()
# call the "perimeter" method
rectangle.perimeter()
访问 yearsList
,因为它是一个 Object(catlogData
)。如果您想迭代整个 catlogData.yearsList
对象,请检查此 answer
试试这个
catlogData