js цикл выводит только первый результат

При получении информации с rest.db.ripe.net цикл выводит только последний результат

{"service" : {
  "name" : "search"
},
"parameters" : {
  "inverse-lookup" : { },
  "type-filters" : { },
  "flags" : { },
  "query-strings" : {
    "query-string" : [ {
      "value" : "46.180.122.12"
    } ]
  },
  "sources" : { }
},
"objects" : {
  "object" : [ {
    "type" : "inetnum",
    "link" : {
      "type" : "locator",
      "href" : "https://rest.db.ripe.net/ripe/inetnum/46.180.0.0 - 46.180.255.255"
    },
    "source" : {
      "id" : "ripe"
    },
    "primary-key" : {
      "attribute" : [ {
        "name" : "inetnum",
        "value" : "46.180.0.0 - 46.180.255.255"
      } ]
    },
    "attributes" : {
      "attribute" : [ {
        "name" : "inetnum",
        "value" : "46.180.0.0 - 46.180.255.255"
      }, {
        "name" : "netname",
        "value" : "GOODLINE-INFO"
      }, {
        "name" : "descr",
        "value" : "E-Light-Telecom"
      }, {
        "name" : "descr",
        "value" : "Russia, Kemerovo, Kuznecky 18"
      }, {
        "name" : "country",
        "value" : "RU"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/person/KK7315-RIPE"
        },
        "name" : "admin-c",
        "value" : "KK7315-RIPE",
        "referenced-type" : "person"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/person/AK22501-RIPE"
        },
        "name" : "tech-c",
        "value" : "AK22501-RIPE",
        "referenced-type" : "person"
      }, {
        "name" : "status",
        "value" : "ASSIGNED PA"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-by",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-lower",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-domains",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-routes",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "name" : "created",
        "value" : "2011-06-22T08:11:59Z"
      }, {
        "name" : "last-modified",
        "value" : "2023-04-28T08:09:45Z"
      }, {
        "name" : "source",
        "value" : "RIPE"
      } ]
    }
  }, {
    "type" : "person",
    "link" : {
      "type" : "locator",
      "href" : "https://rest.db.ripe.net/ripe/person/AK22501-RIPE"
    },
    "source" : {
      "id" : "ripe"
    },
    "primary-key" : {
      "attribute" : [ {
        "name" : "nic-hdl",
        "value" : "AK22501-RIPE"
      } ]
    },
    "attributes" : {
      "attribute" : [ {
        "name" : "person",
        "value" : "Aleksej Korol'kov"
      }, {
        "name" : "address",
        "value" : "Russian Federation"
      }, {
        "name" : "address",
        "value" : "Kemerovo"
      }, {
        "name" : "address",
        "value" : "650099 Kuznetsky 18"
      }, {
        "name" : "phone",
        "value" : "+73842452999"
      }, {
        "name" : "phone",
        "value" : "+73842452893"
      }, {
        "name" : "nic-hdl",
        "value" : "AK22501-RIPE"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-by",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "name" : "created",
        "value" : "2023-03-10T07:32:26Z"
      }, {
        "name" : "last-modified",
        "value" : "2023-03-10T07:32:26Z"
      }, {
        "name" : "source",
        "value" : "RIPE",
        "comment" : "Filtered"
      } ]
    }
  }, {
    "type" : "person",
    "link" : {
      "type" : "locator",
      "href" : "https://rest.db.ripe.net/ripe/person/KK7315-RIPE"
    },
    "source" : {
      "id" : "ripe"
    },
    "primary-key" : {
      "attribute" : [ {
        "name" : "nic-hdl",
        "value" : "KK7315-RIPE"
      } ]
    },
    "attributes" : {
      "attribute" : [ {
        "name" : "person",
        "value" : "Konstantin Karavaev"
      }, {
        "name" : "address",
        "value" : "Russian Federation"
      }, {
        "name" : "address",
        "value" : "Kemerovo"
      }, {
        "name" : "address",
        "value" : "650099 Kuznetsky 18"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/organisation/ORG-EA385-RIPE"
        },
        "name" : "org",
        "value" : "ORG-EA385-RIPE",
        "referenced-type" : "organisation"
      }, {
        "name" : "phone",
        "value" : "+73842452999"
      }, {
        "name" : "phone",
        "value" : "+73842452893"
      }, {
        "name" : "nic-hdl",
        "value" : "KK7315-RIPE"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-by",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "name" : "created",
        "value" : "2018-11-14T03:45:11Z"
      }, {
        "name" : "last-modified",
        "value" : "2018-11-14T03:53:45Z"
      }, {
        "name" : "source",
        "value" : "RIPE",
        "comment" : "Filtered"
      } ]
    }
  }, {
    "type" : "route",
    "link" : {
      "type" : "locator",
      "href" : "https://rest.db.ripe.net/ripe/route/46.180.96.0/19AS39927"
    },
    "source" : {
      "id" : "ripe"
    },
    "primary-key" : {
      "attribute" : [ {
        "name" : "route",
        "value" : "46.180.96.0/19"
      }, {
        "name" : "origin",
        "value" : "AS39927"
      } ]
    },
    "attributes" : {
      "attribute" : [ {
        "name" : "route",
        "value" : "46.180.96.0/19"
      }, {
        "name" : "descr",
        "value" : "Goodline.info"
      }, {
        "name" : "origin",
        "value" : "AS39927"
      }, {
        "link" : {
          "type" : "locator",
          "href" : "https://rest.db.ripe.net/ripe/mntner/ELT-MNT"
        },
        "name" : "mnt-by",
        "value" : "ELT-MNT",
        "referenced-type" : "mntner"
      }, {
        "name" : "created",
        "value" : "2010-12-22T11:28:32Z"
      }, {
        "name" : "last-modified",
        "value" : "2010-12-22T11:28:32Z"
      }, {
        "name" : "source",
        "value" : "RIPE"
      } ]
    }
  } ]
},
"terms-and-conditions" : {
  "type" : "locator",
  "href" : "https://apps.db.ripe.net/docs/HTML-Terms-And-Conditions"
},
"version" : {
  "version" : "1.109.1",
  "timestamp" : "2023-12-06T15:18:06Z",
  "commit-id" : "acc20f7"
}
}
const fetch = require('node-fetch')
fetch('http://rest.db.ripe.net/search.json?query-string=46.180.122.12')
.then(res => res.json())
  .then(res => {
    function getData() {
      let content = [];
      let i = 0;
      let j = 0;
      let json = res;
      let h = []     
      for (i = 0; i < json['objects']['object'].length; i++) {
        for (j = 0; j < json['objects']['object'][i]['attributes']['attribute'].length; j++) {
            //console.log(json['objects']['object'][i]['attributes']['attribute'][j]['name'])
          switch (json['objects']['object'][i]['attributes']['attribute'][j]['name']) {
            case 'country':
              {
                content['country'] = json['objects']['object'][i]['attributes']['attribute'][j]['value'];
              };
              break;
            case 'address':
              {
                content['address'] = json['objects']['object'][i]['attributes']['attribute'][j]['value'];   

              };
              break;
            case 'phone':
              {
                content['phone'] = json['objects']['object'][i]['attributes']['attribute'][j]['value'];
              };
              break;
            case 'person':
              {
                content['person'] = json['objects']['object'][i]['attributes']['attribute'][j]['value'];
              };
              break;
          }
        }
      }
      return content;
    }
    let getI = getData()
    console.log(getI)
  });

Результат: [ country: 'RU', person: 'Konstantin Karavaev', address: '650099 Kuznetsky 18', phone: '+73842452893' ]

Согласно WHOIS: address: Russian Federation address: Kemerovo address: 650099 Kuznetsky 18

Аналогичная ситуация и с кейсом phone... каким образом получать все поля address, чтобы результат был к примеру: Russian Federation, Kemerovo, 650099 Kuznetsky 18. Полей с address может быть как 1 так и 10..


Ответы (0 шт):