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>
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.