Reputation: 271
I have a json object returned from an api and want to create an interface with fields that the object contains. I am using ionic 3 framework. I want help in how to create this interface.( i am confused: should i create another interface for data? and how to include it in the main interface if yes?) the object structure is as follows:
{
"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",
}
}
}
]
}
Upvotes: 1
Views: 384
Reputation: 3130
If you're defining interfaces, you should define one for each object in your response. You don't have to, but to get proper type completion, you should.
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;
}
Upvotes: 3