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

136
Visualizações
Get and print informations from Json File in HTML website

I need to create a basic website where I have to print informations from a Json file. With Javascript.

What I would like to have it's, the picture of the results

But I have no idea how to do that cause I'm a beginner in Javascript. Can you help me please ? Thanks a lot Theo

{
    "number_of_results": 20,
    "results": [
        {
            "name": {
                "first": "Test",
                "last": "Test"
            },
            "date_of_birth": {
                "date": "1985-12-03T02:05:33",
                "age": 36
            },
            "picture": {
                "large": "apple.png",
            },
        },
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It appears that your data structure doesn't quite match what you had in your script so some of the corrections here (from your version) are:

  • change .firstName to .name.first
  • reference results array so results.name becomes results[i].name
  • email shows undefined but that's because it is not in the data (at least not in your example)
  • the image tag shows up with the right source, but because those are not full urls, the image will likely appear broken until the data is more realistic.

The following script should append both the div with the name/email and the image.

function appendData(data) {
    var mainContainer = document.getElementById("myData");
    for (var i = 0; i < data.results.length; i++) {
        var div = document.createElement("div");
        div.innerHTML = 'Email: ' + data.results[i].email + ' First Name :' + data.results[i].name.first;
        mainContainer.appendChild(div);
        var img = document.createElement("img");
        img.src = data.results[i].picture.large;
        mainContainer.appendChild(img);
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Try This:

function appendData(data) {
    var mainContainer = document.getElementById("myData");
    for (var i = 0; i < data.results.length; i++) {
        var div = document.createElement("div"); 
        div.innerHTML = 'Email: ' + (data.results[i].email?data.results[i].email:'') + ' First Name :' + (data.results[i].name?data.results[i].name.first:'');
        mainContainer.appendChild(div);
    }
}
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