I am trying to parse data. But this error comes:
Error parsing response TypeError: Cannot read properties of undefined (reading 'response')
var result:
{
multistatus: {
'$': { xmlns: 'DAV:', 'xmlns:C': 'urn:ietf:params:xml:ns:caldav' },
response: [ [Object], [Object] ]
}
}
Code:
var data = result['D:multistatus']['D:response'];
if(data) {
data.map((event) => {
var ics = event['D:propstat'][0]['D:prop'][0]['C:calendar-data'][0];
var jcalData = ICAL.parse(ics);
var vcalendar = new ical.Component(jcalData);
var vevent = vcalendar.getFirstSubcomponent('vevent');
reslist.push(vevent)
});
}
Error:
Error parsing response TypeError: Cannot read properties of undefined (reading 'response')
(Error to the line var data ...)
i expected to parse the data on correctly. Afterwards the events get filtered again.
You data structure is this:
Which means you should use the actual property names
multistatusandresponseand change this:to this:
I don't know why you put the
D:at the front of the property names. Those are not present in the actual property names you show and must be removed.Also, you should not be using
varany more. Use eitherletorconst.The error message you get:
Comes because this first part:
results in
undefined(since theD:multistatusproperty does not exist) and then you try to reference the second property offundefined, with this:you get that error as
undefinedis not an object and thus gives you an error when you try to reference a property on it.