Javascript 对象类型脚本/3的接口
我有一个从api返回的json对象,希望创建一个包含该对象所包含字段的接口。我使用的是离子3框架。我希望获得有关如何创建此接口的帮助。(我感到困惑:我应该为数据创建另一个接口吗?如果是,如何将其包含在主接口中?)对象结构如下:Javascript 对象类型脚本/3的接口,javascript,typescript,ionic-framework,ionic3,Javascript,Typescript,Ionic Framework,Ionic3,我有一个从api返回的json对象,希望创建一个包含该对象所包含字段的接口。我使用的是离子3框架。我希望获得有关如何创建此接口的帮助。(我感到困惑:我应该为数据创建另一个接口吗?如果是,如何将其包含在主接口中?)对象结构如下: { "status": "success", "data": [ { "id": 113, "subject": "hello there", "body": "i am hisham",
{
"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",
}
}
}
]
}
如果要定义接口,则应该为响应中的每个对象定义一个接口。您不必这样做,但要获得正确的类型完成,您应该这样做
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;
}