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

378
Visualizações
Reading a JSON file: Fix with square brackets [ ] with javascript

any way to read a JSON file with rectangle brackets with javascript

example:

[{"c_title":"Sachertorte","c_startdate":1586941500000,"c_enddate":1586945100000,"c_location":"Dortmund","c_isallday":0,"c_description":"Logineo-Konferenz","calendarRange":null},{"c_title":"Ende der Osterferien","c_startdate":1587333600000,"c_enddate":1587419999000,"c_location":"","c_isallday":0,"c_description":"","calendarRange":null}]

I have this code in javascript to read the json but without the rectangular brackets

<body>
    <div class="mypanel"></div>

    <script>
    $.getJSON('', function(data) {

        var text = `Date: ${data.c_title}<br>
                    Time: ${data.c_startdate}<br>
                    Unix time: ${data.c_enddate}`


        $(".mypanel").html(text);
    });
    </script>

</body>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Technically the square brackets indicate that this is an array with one object item in it.

Therefore in order to really use it this way you'd need to read the data this way:

var text = `Date: ${data[0].c_title}<br>
            Time: ${data[0].c_startdate}<br>
            Unix time: ${data[0].c_enddate}`

The [0] means you're grabbing the item at index 0 in the array (i.e. the first - and only - item).

This will obviously ignore any additionally items in the array, but if you're only ever expecting one object in the array then this will work fine.

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