Relative Content

Tag Archive for reactjsjsontypescriptxml

JSON object is undefined in some scenarios, normal in others

I’m making a web app with ReactJS that uses the BoardGameGeek API. This API returns XML files, so I have been converting them into JSON and then parsing them. In some cases, the JSON object works perfectly, like when I render <pre>{JSON.stringify(xmlData, null, 4)}</pre>, where xmlData is the JSON object. However, when I try to access a specific element with console.log(xmlData?.items.item[i].name._value), I only get undefined. The thing that is really confusing to me is that there are no issues in another file with seemingly the exact same methodology for parsing XML.