Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对象类型脚本/3的接口_Javascript_Typescript_Ionic Framework_Ionic3 - Fatal编程技术网

Javascript 对象类型脚本/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",

我有一个从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",
              }

          }

      }

  ]

}

如果要定义接口,则应该为响应中的每个对象定义一个接口。您不必这样做,但要获得正确的类型完成,您应该这样做

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;
}