Trying to get return value from JSON.parse
I was looking at a horrible example on the mozilla.org page and trying to use it, but since their example is unrealistic I don't quite get it. How do I read the return value? I think the brackets are the problem. I could write some sloppy code to remove them, but is there a better way?
For the time being I got rid of the brackets using substring. Not very elegant.
var x = data.substring(1,data.length-1); // get rid of the brackets around the json value
- try {
alert(data); // [{"result":"case not found!"}]
var objArray = JSON.parse(data, (key, value) => typeof value === 'string' ? value : value);
}
catch (err1) {
alert('Save Match ' + err.message);
}
//$("#txtError4").val(objArray['result']);
alert(objArray['result']); // undefined
alert(objArray[0]); // [object Object]