Hi,
I am using the JS API on 4.16.0 to get the parents of an asset (using the getParents method). I am specifically looking for parents of a certain type and with a certain link value so sometimes there are none.
When the ajax call comes back and http.responseText is about to be returned, it is sent through jsonToObj first for formatting purposes.
However, if the asset has no parents then http.responseText is empty and so the JSON.parse method fails with a syntax error ("Unexpected end of input").
The existing function is below (with additional comment from me).
Does anyone know whether this has been fixed in a later version?
Thanks,
Graham
/** * Convert a JSON string to object */ function jsonToObj(json) { // Make the conversion if (typeof(JSON) !== 'undefined') { // Needs a check for empty string here! return JSON.parse(json); }// end if// Don’t worry, even the creator of JSON says eval is ok here
return eval(’(’ + json + ‘)’);}// end jsonToObj