Question
JSON parse error on undefined object
I'm currently attempting to pass a json string to a jsx file so that I could parse it and do something with it in the script.
I evaluate json2.js like so:
const json2File = `${root}/js/json2.js`;
csiRun.evalScript(`$.evalFile('${json2File}')`);I evaluate a script like so:
$('#create-html').click(function() {
csiRun.evalScript(`setupArtTemplate()`, jsxResult => {
csiRun.evalScript(`main('${jsxResult}')`);
});
})In my script I then try to parse the data like so:
function main(layoutDetails) {
try {
var detailsParsed = JSON.parse(layoutDetails);
} catch (error) {
alert(layoutDetails);
alert('Cannot parse data, error: ' + error)
}
}The error I receive is
Cannot parse data, error: TypeError: undefined is not an objectHowever as you can see I alert layoutDetails which does show the object as a json string. But it doesn't parse. Any idea what I'm doing wrong?