我有一个从api返回的json对象,并希望使用对象包含的字段创建一个接口。我使用的是离子3框架。我需要帮助如何创建这个接口。(我很困惑:我应该为数据创建另一个接口吗?)如果是的话,如何将其包含在主界面中?)对象结构如下:
{
"status": "success",
"data": [
{
"id": 113,
"subject": "hello there",
"body": "i am hisham",
"sender": {
"id": 51,
"country": {
"id": 9,
"name_en": "Syria",
}
}
},
{
"id": 114,
"subject": "hello there",
"body": "i am lkfdj",
"sender": {
"id": 54,
"country": {
"id": 9,
"name_en": "Syria",
}
}
}
]
}发布于 2018-06-14 22:33:44
如果要定义接口,则应该为响应中的每个对象定义一个接口。你不必这么做,但要想完成正确的类型,你应该。
interface Response {
status: string;
data: Data[];
}
interface Data {
id: number;
subject: string;
body: string;
sender: Sender;
}
interface Sender {
id: number;
country: Country;
}
interface Country {
id: number;
name_en: string;
}https://stackoverflow.com/questions/50866790
复制相似问题