Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Teleport API: Access JSON Object properties

I am learning some things about API calls in Javascript. For this, I make a call to the teleport api.

From there I get an Json object back. Now I would like to access the link which you can see in the "json object" below.

_embedded
    city:search-results     [25]
    0
    _links
    city:item
    href:   https://api.teleport.org/api/cities/geonameid:2661552/
    

I have a problem with the "city:search-results" key, because I cant use a the ":" in the dotted notation.

so, how can I get the href value?

I hope its understandable, im sorry for the bad explanation. Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I see how the JSON is returned. For this example, use bracket notation for city:search-results as

_embedded["city:search-results"][0]

And for accessing the href property:

_embedded["city:search-results"][0]["_links"]["city:item"]["href"]

Example code (with 2 city:search-results objects):

var _embedded = {
  "city:search-results": [{
      "_links": {
        "city:item": {
          "href": "https://api.teleport.org/api/cities/geonameid:1796236/"
        }
      },
      "matching_alternate_names": [],
      "matching_full_name": "Shanghai, Shanghai, China"
    },
    {
      "_links": {
        "city:item": {
          "href": "https://api.teleport.org/api/cities/geonameid:745044/"
        }
      },
      "matching_alternate_names": [],
      "matching_full_name": "Istanbul, Istanbul, Turkey"
    }
  ]
};
console.log(_embedded["city:search-results"][0]["_links"]["city:item"]["href"]);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda